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
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
mixed_fraction-0.1.0.tar.gz
(3.5 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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bbded5fa4902c2e584b4bed2dc37b0d11bc2f1d150fbfa98947687a7d76d207
|
|
| MD5 |
9e9a1188e239ccc8edd9e0ad99b16eb9
|
|
| BLAKE2b-256 |
2ed8085f7ce353f0a6e4b90b5985ab7b7a323ad1ac80bbefe9de93b3dbe367fe
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ead9dd58e46c9afe5ba71c44bc7a1d0714f593e3ea952d34e3cc6b20b507c39
|
|
| MD5 |
2fdb960efaf76f42f3b7ad3418aaf022
|
|
| BLAKE2b-256 |
148031d80d63b49179f80c145e572f488c978268e3698d20abeaec3e170e6b09
|