Skip to content

This repository contains a Python script for a Fraction class, which provides various methods for performing arithmetic operations and type conversion on fractions. It also includes dunder methods for comparison operators such as greater than, less than, equal to, etc. The purpose is to demonstrate the implementation of a custom class in Python.

Notifications You must be signed in to change notification settings

usmananwaar-de/class-fraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Fraction Class

The Fraction class is a Python class that represents a fraction with a numerator and denominator. It provides methods for performing arithmetic operations, comparing fractions, and converting fractions to different types.

Installation

To use the Fraction class, simply download or clone the project from the GitHub repository. The Fraction class is contained in the fraction.py file.

Usage

  • To use the Fraction class, simply import it into your Python script:
from fractions import Fraction
  • Then you can create new Fraction objects by calling the constructor:
f1 = Fraction(1, 2)
f2 = Fraction(3, 4)
  • You can perform arithmetic operations on fractions using the standard operators:
f3 = f1 + f2
f4 = f1 - f2
f5 = f1 * f2
f6 = f1 / f2
f7 = f1 // f2
  • You can compare fractions using the comparison operators:
f8 = f1 > f2
f9 = f1 >= f2
f10 = f1 == f2
f11 = f1 != f2
  • You can convert fractions to different types using the type conversion methods:
f12 = abs(f1)
f13 = int(f1)
f14 = float(f1)
f15 = round(f1, 2)
f16 = trunc(f1)
f17 = ceil(f1)
f18 = floor(f1)

Contributions

If you believe you can contribute to the project, clone the repo and submit your changes.

About

This repository contains a Python script for a Fraction class, which provides various methods for performing arithmetic operations and type conversion on fractions. It also includes dunder methods for comparison operators such as greater than, less than, equal to, etc. The purpose is to demonstrate the implementation of a custom class in Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages