Skip to main content

A Python class for working with fractions

Project description

DoonFraction

A Python class for working with fractions. The doonfraction class allows you to create instances of fractions, perform arithmetic operations with them, and convert them to floating point numbers.

Examples

from doonfraction.doonfraction import doonfraction

# Create a fraction
f = doonfraction(3, 4)

# Perform arithmetic operations with fractions
f1 = doonfraction(1, 2)
f2 = doonfraction(1, 4)
f3 = f1 + f2
print(f3)  # prints "3/4"

f4 = f1 - f2
print(f4)  # prints "1/4"

f5 = f1 * f2
print(f5)  # prints "1/8"

f6 = f1 / f2
print(f6)  # prints "2/1"

# Convert a fraction to a float
f7 = doonfraction(1, 2)
print(float(f7))  # prints 0.5


# Convert fraction to mixed fraction
f8=doonfraction(7,2)
f9=f8.mixf()
print(f9)  #prints "3 1/2"


## 

__init__(self, num, den): Constructor to initialize the numerator and denominator.

__str__(self): Returns the string representation of the fraction in the form of "numerator/denominator".

__add__(self, other): Adds two fractions and returns the result as a new doonfraction instance.

__sub__(self, other): Subtracts two fractions and returns the result as a new doonfraction instance.

__mul__(self, other): Multiplies two fractions and returns the result as a new doonfraction instance.

__truediv__(self, other): Divides two fractions and returns the result as a new doonfraction instance.

__float__(self): Converts the fraction to a floating point number.

mixf(self): Convert a fraction to a mixed fraction

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

doonfraction-1.0.2.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

doonfraction-1.0.2-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file doonfraction-1.0.2.tar.gz.

File metadata

  • Download URL: doonfraction-1.0.2.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for doonfraction-1.0.2.tar.gz
Algorithm Hash digest
SHA256 67586fad0165227819c3baff01a89b7a1cf4b286dc68dadc739b7e5708505e17
MD5 731a33d0a1800e65010c4d48ae32a1c4
BLAKE2b-256 3920a41708a49dc54e35e37b9e863743e9a8c511552435233e5c1382725d9585

See more details on using hashes here.

File details

Details for the file doonfraction-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: doonfraction-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for doonfraction-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c64de9cbe5c438c37f0632a26dc4fc9f4705850938e02edd37bd7ebb28c4fb2a
MD5 113401ccf1fe1ea094ed9d01d389cd6a
BLAKE2b-256 004dec9cdab6d9bc2bc3ec190bd9f6faa595b0312a78f8d81237eff3682737bc

See more details on using hashes here.

Supported by

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