Fraction carries out all the fraction operations including addition, subtraction, multiplication, division, reciprocation
Project description
fraction
fraction is a Python module that is designed for fractional values numerator/denominator
Installation
Easy to install
$ sudo pip install Fraction
Usage
>>> from fraction.Fraction import Fraction
Creates a fraction equal to 0/1
>>> def_fraction = Fraction()
Creates a fraction equal to 3/10
>>> a = Fraction(3, 10)
>>> b = Fraction(1, 2)
# Get numerator/denominator
>>> a.numerator, a.denominator
(3, 10)
Computes reciprocal of fraction as Fraction object
>>> recip_a = Fraction.reciprocal(a)
>>> recip_a.numerator, recip_a.denominator
(10, 3)
Perform addition of Fraction objects (returns a Fraction object)
>>> sum_ab = a + b
>>> sum_ab.numerator, sum_ab.denominator
(4, 5)
Perform subtraction of Fraction objects (returns a Fraction object)
>>> diff_ab = a - b
>>> diff_ab.numerator, diff_ab.denominator
(-1, 5)
Perform multiplication of Fraction objects (returns a Fraction object)
>>> mul_ab = a * b
>>> mul_ab.numerator, mul_ab.denominator
(3, 20)
Perform div of Fraction objects (returns a Fraction object)
>>> div_ab = a / b
>>> div_ab.numerator, div_ab.denominator
(3, 5)
Comparison/Relational operations
Supports comparison operations [<, <=, >, >=, ==, !=] (returns boolean)
>>> a < b
True
>>> a == Fraction(7, 10)
False
For debugging
Supports str() and repr() built in objects methods
>>> a = Fraction()
>>> print a
0/1
>>> a
Fraction: 0/1
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
Fraction-1.2.0.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file Fraction-1.2.0.tar.gz
.
File metadata
- Download URL: Fraction-1.2.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b4e815b7161a70ac0496ebf4f2fa5c6c22ca957b3d775455cf37a4e026f1e6 |
|
MD5 | 951635f10418c50659111e20122dc385 |
|
BLAKE2b-256 | 30b22956191783bfcdb62bfd2ffe75344a3cc654e1c849c07b03618c97c0b6bd |
File details
Details for the file Fraction-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: Fraction-1.2.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 370fa9ec42550e4f98233a003bb0a2651a3ae93eeee8d803fb7d9050a35e6044 |
|
MD5 | 55da908f863cfd50fac77344b9dcefa2 |
|
BLAKE2b-256 | 32e27389c2716ec289d33d28f4978632f7ad6e1a0df04604531e47bf7e7d60ff |