prop-cli 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
prop_cli-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Domenico Bruno "Lobkowitz"
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: prop-cli
3
+ Version: 1.0.0
4
+ Summary: A simple command-line proportion solver (rule of three)
5
+ Author-email: "Domenico Bruno \"Lobkowitz\"" <blobkowitz@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Operating System :: OS Independent
8
+ Requires-Python: >=3.6
9
+ License-File: LICENSE
10
+ Dynamic: license-file
@@ -0,0 +1,122 @@
1
+ # prop-cli
2
+
3
+ A simple command-line tool that solves proportions of the form:
4
+
5
+ a : b = c : d
6
+
7
+ where one of the terms is unknown (`x`).
8
+ This is the classic **rule of three**, a fundamental arithmetic technique for solving proportions by cross-multiplication.
9
+
10
+ ---
11
+
12
+ ## Installation
13
+
14
+ Clone the repository and install locally:
15
+
16
+ pip install .
17
+
18
+ This will install the `prop-cli` command.
19
+
20
+ ---
21
+
22
+ ## Usage
23
+
24
+ prop-cli <a> <b> <c> <d>
25
+
26
+ Example:
27
+
28
+ prop-cli 10 12 x 30
29
+
30
+ Output:
31
+
32
+ Proportion: 10:12 = 25:30
33
+ x = 25
34
+
35
+ You can put `x` in any of the four positions:
36
+
37
+ prop-cli x 5 6 12
38
+ prop-cli 2 x 4 8
39
+ prop-cli 3 9 x 27
40
+ prop-cli 4 5 0.1 x
41
+
42
+ ---
43
+
44
+ ## How cross-multiplication works
45
+
46
+ To solve a proportion of the form:
47
+
48
+ a : b = c : d
49
+
50
+ we use **cross-multiplication**, which states that:
51
+
52
+ a × d = b × c
53
+
54
+ This is the fundamental property of proportions.
55
+
56
+ ### Visual ASCII diagram
57
+
58
+ a : b = c : d
59
+ │ │
60
+ │ │
61
+ └───┬───┘
62
+ │
63
+ Cross-multiplication
64
+ │
65
+ a × d = b × c
66
+
67
+ ### Solving for an unknown (example)
68
+
69
+ If one term is unknown (`x`), we isolate it using the cross-multiplication identity.
70
+
71
+ Case: the unknown is in the second position (`x`):
72
+
73
+ a : x = c : d
74
+ │ │
75
+ │ │
76
+ └───┬───┘
77
+ │
78
+ a × d = x × c
79
+ │
80
+ └──→ x = (a × d) / c
81
+
82
+ Another case: unknown in the fourth position (`x`):
83
+
84
+ a : b = c : x
85
+ │ │
86
+ │ │
87
+ └───┬───┘
88
+ │
89
+ a × x = b × c
90
+ │
91
+ └──→ x = (b × c) / a
92
+
93
+ This tool automatically:
94
+ - identifies where the `x` is,
95
+ - applies the correct formula,
96
+ - prints the solved proportion and the computed value.
97
+
98
+ ---
99
+
100
+ ## Error handling
101
+
102
+ The tool validates:
103
+ - only one unknown term (`x`)
104
+ - all other terms must be valid numbers
105
+ - division by zero is caught with clear error messages
106
+
107
+ ---
108
+
109
+ ## Project structure
110
+
111
+ prop-cli/
112
+ ├── pyproject.toml
113
+ ├── README.md
114
+ └── proportion_calculator/
115
+ ├── cli.py
116
+ └── __init__.py
117
+
118
+ ---
119
+
120
+ ## License
121
+
122
+ MIT License
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: prop-cli
3
+ Version: 1.0.0
4
+ Summary: A simple command-line proportion solver (rule of three)
5
+ Author-email: "Domenico Bruno \"Lobkowitz\"" <blobkowitz@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Operating System :: OS Independent
8
+ Requires-Python: >=3.6
9
+ License-File: LICENSE
10
+ Dynamic: license-file
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ prop_cli.egg-info/PKG-INFO
5
+ prop_cli.egg-info/SOURCES.txt
6
+ prop_cli.egg-info/dependency_links.txt
7
+ prop_cli.egg-info/entry_points.txt
8
+ prop_cli.egg-info/top_level.txt
9
+ proportion_calculator/__init__.py
10
+ proportion_calculator/cli.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ prop-cli = proportion_calculator.cli:main
@@ -0,0 +1 @@
1
+ proportion_calculator
@@ -0,0 +1,5 @@
1
+ # ============================================
2
+ # File: proportion_calculator/__init__.py
3
+ # ============================================
4
+ """Calcolatore di proporzioni."""
5
+ __version__ = "1.0.0"
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env python3
2
+ """Proportion calculator for expressions of the form a:b = c:d."""
3
+
4
+ import sys
5
+ from typing import Optional
6
+
7
+
8
+ def fmt(value: float) -> str:
9
+ """Format numbers without scientific notation."""
10
+ s = f"{value:.12f}".rstrip("0").rstrip(".")
11
+ return s if s != "-0" else "0"
12
+
13
+
14
+ def solve_proportion(a_str: str, b_str: str, c_str: str, d_str: str) -> Optional[float]:
15
+ """
16
+ Solves a proportion a:b = c:d given as strings.
17
+ One of the four values must be 'x'.
18
+ """
19
+ terms = [a_str, b_str, c_str, d_str]
20
+
21
+ # Find position of the unknown 'x'
22
+ x_positions = [i for i, term in enumerate(terms) if term.lower() == "x"]
23
+
24
+ if len(x_positions) == 0:
25
+ print("Error: No 'x' found. One term must be the unknown.")
26
+ return None
27
+ if len(x_positions) > 1:
28
+ print("Error: Only one unknown 'x' is allowed.")
29
+ return None
30
+
31
+ x_pos = x_positions[0]
32
+
33
+ try:
34
+ # Convert numeric values
35
+ a, b, c, d = [None if i == x_pos else float(term) for i, term in enumerate(terms)]
36
+
37
+ # Compute depending on the unknown position
38
+ if x_pos == 0:
39
+ if d == 0:
40
+ print("Error: Division by zero (d = 0).")
41
+ return None
42
+ x = (b * c) / d
43
+ elif x_pos == 1:
44
+ if c == 0:
45
+ print("Error: Division by zero (c = 0).")
46
+ return None
47
+ x = (a * d) / c
48
+ elif x_pos == 2:
49
+ if b == 0:
50
+ print("Error: Division by zero (b = 0).")
51
+ return None
52
+ x = (a * d) / b
53
+ else: # x_pos == 3
54
+ if a == 0:
55
+ print("Error: Division by zero (a = 0).")
56
+ return None
57
+ x = (b * c) / a
58
+
59
+ result = [a, b, c, d]
60
+ result[x_pos] = x
61
+
62
+ print(f"Proportion: {fmt(result[0])}:{fmt(result[1])} = {fmt(result[2])}:{fmt(result[3])}")
63
+ print(f"x = {fmt(x)}")
64
+
65
+ return x
66
+
67
+ except ValueError:
68
+ print("Error: Only numbers or 'x' are allowed.")
69
+ return None
70
+
71
+
72
+ def print_usage() -> None:
73
+ print("--- Proportion Calculator (a:b = c:d) ---")
74
+ print("Usage: prop-cli <a> <b> <c> <d>")
75
+ print("Example: prop-cli 10 12 x 30")
76
+ print("Note: Use 'x' for the unknown term.")
77
+
78
+
79
+ def main() -> int:
80
+ if len(sys.argv) != 5:
81
+ print_usage()
82
+ return 1
83
+
84
+ result = solve_proportion(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
85
+ return 0 if result is not None else 1
86
+
87
+
88
+ if __name__ == "__main__":
89
+ sys.exit(main())
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "prop-cli"
7
+ version = "1.0.0"
8
+ description = "A simple command-line proportion solver (rule of three)"
9
+ authors = [
10
+ { name = "Domenico Bruno \"Lobkowitz\"", email = "blobkowitz@gmail.com" }
11
+ ]
12
+ requires-python = ">=3.6"
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+
18
+ [project.scripts]
19
+ prop-cli = "proportion_calculator.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+