Skip to main content

Fraction carries out all the fraction operations including addition, subtraction, multiplication, division, reciprocation

Project description

fraction PyPI - Downloads

fraction is a Python module that is designed for fractional values numerator/denominator

Installation

Easy to install

$ sudo pip install Fraction

Usage

>>> from 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


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.4.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

Fraction-1.4.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file Fraction-1.4.1.tar.gz.

File metadata

  • Download URL: Fraction-1.4.1.tar.gz
  • Upload date:
  • Size: 2.6 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.3

File hashes

Hashes for Fraction-1.4.1.tar.gz
Algorithm Hash digest
SHA256 140ae9b131e7516e873e6daccd3c9e90a223c14e42b59fdca906e3272b0f1916
MD5 3efc2280cb919e13484da9ca15f8c828
BLAKE2b-256 e6a316530f8553a6efe0750fc87f5b4b74d9d5163cd162b957481c8c3e03e303

See more details on using hashes here.

File details

Details for the file Fraction-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: Fraction-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 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.3

File hashes

Hashes for Fraction-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4eec72c0dd0a19a864633b751bfeed86d46ec49fbcfce8e92d287c2d4b472079
MD5 583107e60abdd380776867436cc05d38
BLAKE2b-256 32f49e69e9014900791e1311b9c9d3d6c6b4a869aef067397b2e62448d00123f

See more details on using hashes here.

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