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


## Methods

__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


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.tar.gz (2.2 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-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: doonfraction-1.0.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

Hashes for doonfraction-1.0.tar.gz
Algorithm Hash digest
SHA256 81978dad0d8d0b9698aa627606012249d2c475c30329cabea858115eea6b0b52
MD5 a5d0ebc598a145c7b61972464a8ef92a
BLAKE2b-256 beff3ad0872418a8a6365e6c8c792dd814cb2889ac0ef92256d187a49e6a3a25

See more details on using hashes here.

File details

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

File metadata

  • Download URL: doonfraction-1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 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-py3-none-any.whl
Algorithm Hash digest
SHA256 fe57096921246e8558b1cafdfb56097f455b0bc1d64619510edfee02a8993f84
MD5 74e74350c5bd20c3bea1c440ccaaf81c
BLAKE2b-256 c7296ce3b3b44b3bbb9d4c00ad0a93b5932c01e2a45f5bd3881ef9e0b782ef9e

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