A Python project that demonstrates Object-Oriented Programming (OOP) by creating a custom Fraction class. The project uses operator overloading to perform arithmetic operations on fractions just like built-in numeric types.
- Create fraction objects
- Addition of fractions
- Subtraction of fractions
- Multiplication of fractions
- Division of fractions
- Operator overloading using Python magic methods
- Clean and readable OOP implementation
- Python Classes & Objects
- Constructors (
__init__) - Magic Methods
__str____add____sub____mul____truediv__
- Object-Oriented Programming (OOP)
fraction.py
README.md
a = Fraction(5, 4)
b = Fraction(4, 3)
print(a + b)
print(a - b)
print(a * b)
print(a / b)5/4 + 4/3 = 31/12
5/4 - 4/3 = -1/12
5/4 * 4/3 = 20/12
5/4 / 4/3 = 15/16
This project helped me understand:
- How classes and objects work in Python
- Operator overloading using magic methods
- Creating custom data types
- Implementing arithmetic operations with OOP
- Simplify fractions automatically
- Validate denominator (prevent zero division)
- Compare fractions using comparison operators
- Convert fractions to decimal values
Nayan Samadhiya
Aspiring AI/ML Engineer | Learning Python & Object-Oriented Programming