https://github.com/coderatul/fraction
Represents a fraction with a numerator and denominator.
https://github.com/coderatul/fraction
Last synced: 10 months ago
JSON representation
Represents a fraction with a numerator and denominator.
- Host: GitHub
- URL: https://github.com/coderatul/fraction
- Owner: coderatul
- Created: 2023-12-30T19:07:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-03T08:23:47.000Z (almost 2 years ago)
- Last Synced: 2025-02-23T01:47:46.658Z (11 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fraction Calculator
[](https://badge.fury.io/py/pyfractions)
The Fraction Calculator is a versatile Python library designed for performing various operations in ```numerator/denominator``` format. It enables users to work with fractions seamlessly and includes features like basic arithmetic operations, comparison methods, and more.
## Features
- **Basic Arithmetic Operations:**
- Addition
- Subtraction
- Multiplication
- Division
- Floor Division
- Modulus
- **Comparison Methods:**
- Compare fractions using the following methods:
- Less than (`<`)
- Less than or equal to (`<=`)
- Equal to (`==`)
- Not equal to (`!=`)
- Greater than (`>`)
- Greater than or equal to (`>=`)
## Usage
To utilize the Fraction Calculator, create instances of the `Fraction` class and perform operations. Here's an example showcasing basic usage:
```python
from pyfractions import Fraction
# Create Fraction objects
fraction1 = Fraction(1, 2)
fraction2 = Fraction(3, 4)
# Perform operations
sum_result = fraction1 + fraction2
difference_result = fraction1 - fraction2
product_result = fraction1 * fraction2
quotient_result = fraction1 / fraction2
# Display results
print(f'Sum: {sum_result}') # Sum: 5/4
print(f'Difference: {difference_result}') # Difference: -1/4
print(f'Product: {product_result}') # Product: 3/8
print(f'Quotient: {quotient_result}') # Quotient: 2/3
# Check if fraction1 is greater than fraction2
is_greater = fraction1 > fraction2
# Display result
print(f'Is fraction1 greater than fraction2? {is_greater}')
# Is fraction1 greater than fraction2? False
```