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 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
##
__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.
__div__(self, other): Divides two fractions and returns the result as a new doonfraction instance.
__float__(self): Converts the fraction to a floating point number.
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(2.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file doonfraction-1.0.1.tar.gz.
File metadata
- Download URL: doonfraction-1.0.1.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a606254daea33ec1c085ed47b6716947f85b2384a291c82325bbfeb3042e8420
|
|
| MD5 |
726187141d601fe539d3e6688ad6e434
|
|
| BLAKE2b-256 |
e41d955324bcdfac904696be22a5a14af0d4d67a27a30253de7837589579966a
|
File details
Details for the file doonfraction-1.0.1-py3-none-any.whl.
File metadata
- Download URL: doonfraction-1.0.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6c0c0a5d8146456a057c1d43dae709e20cba13a6aea656b68f0feefa4142b65
|
|
| MD5 |
036c31f30814cbe99ff35fe5e985fe7f
|
|
| BLAKE2b-256 |
d301e804b68bf9c945e14de1578fe95918e56070a2deacdd0ee73dc0789d389d
|