Skip to main content

Mixed fraction representation with arithmetic operations

Project description

mixed-fraction

A Python library for working with mixed fractions (integer + proper fraction) with clean ASCII-style formatting and operator support.

Features

  • Mixed fraction representation (integer + fraction)
  • Clean aligned ASCII output
  • Supports addition, subtraction, multiplication, division
  • Built on Python's fractions.Fraction
  • Fully tested with pytest

Installation

pip install mixed-fraction

For local development:
pip install -e .

    Usage

from mixed_fraction import MixedFraction

a = MixedFraction(20, 3)
b = MixedFraction(5, 3)

print(a + b)

    Output:

  1
8   3

    Examples

print(MixedFraction(7, 2))

  1
3   2

print(MixedFraction(88, 7))

   4
12    7

print(MixedFraction(-25, 4))

   1
-6    4

    Error Handling

 Invalid divisor:

MixedFraction(5, 0)

ZeroDivisionError: Divisor cannot be zero.

 Invalid parameter type:

MixedFraction("5", 2)

TypeError: dividend must be an integer

 Invalid operation:

MixedFraction(3, 2) + 5

TypeError: Unsupported operand type(s) for +: 'MixedFraction' and 'int'
    
    Testing

All tests are written using pytest.

Run tests from the project root:

 pytest

 Expected output:

======================== 5 passed in 0.05s ========================
 
 Project Structure

mixed_fraction/
│
├── mixed_fraction/
│   ├── __init__.py
│   └── mixed_fraction.py
│
├── tests/
│   └── test_mixed_fraction.py
│
├── pyproject.toml
├── README.md
└── LICENSE

## License

This project is licensed under the MIT License.  
See the [LICENSE](LICENSE) file for details.

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

mixed_fraction-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

mixed_fraction-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file mixed_fraction-0.1.0.tar.gz.

File metadata

  • Download URL: mixed_fraction-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for mixed_fraction-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8bbded5fa4902c2e584b4bed2dc37b0d11bc2f1d150fbfa98947687a7d76d207
MD5 9e9a1188e239ccc8edd9e0ad99b16eb9
BLAKE2b-256 2ed8085f7ce353f0a6e4b90b5985ab7b7a323ad1ac80bbefe9de93b3dbe367fe

See more details on using hashes here.

File details

Details for the file mixed_fraction-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mixed_fraction-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for mixed_fraction-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ead9dd58e46c9afe5ba71c44bc7a1d0714f593e3ea952d34e3cc6b20b507c39
MD5 2fdb960efaf76f42f3b7ad3418aaf022
BLAKE2b-256 148031d80d63b49179f80c145e572f488c978268e3698d20abeaec3e170e6b09

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