A command-line tool to solve proportions using the rule of three
Project description
prop-cli
A command-line tool that solves proportions of the form:
a : b = c : d
where one term is unknown (x).
The tool uses classic cross-multiplication, also known as the rule of three.
Installation
pip install prop-cli
This installs the command:
prop-cli
Installing from source (local clone)
If you clone this repository manually:
git clone https://github.com/Lobko/prop-cli
cd prop-cli
You can install the package locally with:
pip install .
Or, if you want to install it in development/editable mode:
pip install -e .
This allows you to modify the source code and use the prop-cli command immediately without rebuilding the package.
Usage
prop-cli <a> <b> <c> <d>
Example:
prop-cli 10 12 x 30
Output:
Proportion: 10:12 = 25:30
x = 25
You can place x in any position:
prop-cli x 5 6 12
prop-cli 2 x 4 8
prop-cli 3 9 x 27
prop-cli 4 5 0.1 x
More Examples
prop-cli 5 20 x 120 # x = 30
prop-cli x 4 12 48 # x = 1
prop-cli 3 x 9 15 # x = 5
Edge cases (real ones)
prop-cli 1 x 0 5 # division by zero (c = 0)
prop-cli x 0 3 2 # division by zero (b = 0)
prop-cli 1 2 3 x # valid
How cross-multiplication works
Given the proportion:
a : b = c : d
Rule:
a × d = b × c
Diagram (horizontal)
a : b = c : d
| |
| |
+---+---+
|
Cross-multiplication
|
a × d = b × c
Diagram (vertical rule-of-three)
a c
─── = ───
b d
Cross multiply:
a × d = b × c
Solving when the unknown is in different positions
Unknown in second position
a : x = c : d
a × d = x × c
x = (a × d) / c
Unknown in fourth position
a : b = c : x
a × x = b × c
x = (b × c) / a
Error handling
- Exactly one unknown
xis required - Other terms must be numeric
- Division by zero is detected and reported
- Scientific notation is avoided in output
Project structure
prop-cli/
├── pyproject.toml
├── README.md
├── LICENSE
├── CHANGELOG.md
├── VERSION
├── tests/
│ └── test_basic.py
├── .github/
│ └── workflows/
│ ├── test.yml
│ ├── lint.yml
│ └── build.yml
└── proportion_calculator/
├── cli.py
└── __init__.py
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push the branch
- Open a Pull Request
License
MIT License
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
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 prop_cli-1.0.2.tar.gz.
File metadata
- Download URL: prop_cli-1.0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e688c2ead5504b926246bdab25d3e099953d54820a9974e518d33920ea67b071
|
|
| MD5 |
47fee4936e78f7686c009673d6b48ce7
|
|
| BLAKE2b-256 |
1ef4e1f789360627d2ee7ab58e06032089426d1a1d46c1467019dd3190e9f44b
|
File details
Details for the file prop_cli-1.0.2-py3-none-any.whl.
File metadata
- Download URL: prop_cli-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67a720fecaa7fb55052ee6192a74e0c3ad279aee2ff6d16977f61c015778e9da
|
|
| MD5 |
101a36b63c9adbc7d0b6d92f0f365f2e
|
|
| BLAKE2b-256 |
ee1ffc226bc0e592ea687cccd2a8698126bff7d2753f2167ca8d216c28145871
|