Skip to main content

A command-line tool to solve proportions using the rule of three

Project description

prop-cli

A simple command-line tool that solves proportions of the form:

a : b = c : d

where one of the terms is unknown (x).
This is the classic rule of three, a fundamental arithmetic technique for solving proportions by cross-multiplication.


Installation

Clone the repository and install locally:

pip install .

This will install the prop-cli command.


Usage

prop-cli <a> <b> <c> <d>

Example:

prop-cli 10 12 x 30

Output:

Proportion: 10:12 = 25:30
x = 25

You can put x in any of the four positions:

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

How cross-multiplication works

To solve a proportion of the form:

a : b = c : d

we use cross-multiplication, which states that:

a × d = b × c

This is the fundamental property of proportions.

Visual ASCII diagram

   a : b = c : d
     │       │
     │       │
     └───┬───┘
         │
 Cross-multiplication
         │
   a × d = b × c

Solving for an unknown (example)

If one term is unknown (x), we isolate it using the cross-multiplication identity.

Case: the unknown is in the second position (x):

    a : x = c : d
      │       │
      │       │
      └───┬───┘
          │
  a × d = x × c
          │
          └──→  x = (a × d) / c

Another case: unknown in the fourth position (x):

    a : b = c : x
      │       │
      │       │
      └───┬───┘
          │
  a × x = b × c
          │
          └──→  x = (b × c) / a

This tool automatically:

  • identifies where the x is,
  • applies the correct formula,
  • prints the solved proportion and the computed value.

Error handling

The tool validates:

  • only one unknown term (x)
  • all other terms must be valid numbers
  • division by zero is caught with clear error messages

Project structure

prop-cli/
├── pyproject.toml
├── README.md
└── proportion_calculator/
    ├── cli.py
    └── __init__.py

License

MIT License

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

prop_cli-1.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

prop_cli-1.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file prop_cli-1.0.1.tar.gz.

File metadata

  • Download URL: prop_cli-1.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for prop_cli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b328bba429657b42df951ceb3772591f2af9bdfe0e4826935ff8320a0d6b2e42
MD5 d5f07fd2b4bddc2629c3aa94a5d69592
BLAKE2b-256 015cb0b8ac00fd2be7959fbef779447a5b3d3ebec8b1b70970272995e485ce7d

See more details on using hashes here.

File details

Details for the file prop_cli-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: prop_cli-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for prop_cli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28a22d58f5a47cacc411ed4e3a65662989600d7840f3ad4a2183c13a320ae33b
MD5 0774162c4deb79b90575fc165c9fdaee
BLAKE2b-256 5cd91fd888c33b2783ad875c69144e89b37fb8341f4a75e16d44c3e344c3aba6

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