Skip to main content

A Python library for working with fractions

Project description

Fraction Calculator

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:

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfractions-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

pyfractions-0.1.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page