prop-cli 1.0.0__py3-none-any.whl

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.
@@ -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,8 @@
1
+ prop_cli-1.0.0.dist-info/licenses/LICENSE,sha256=yrwp5UfE6abA63MRNGKmy74MAOGFsu0aXTzXImbBXRo,1082
2
+ proportion_calculator/__init__.py,sha256=39mWSGt2m5uJ5OAD9ZjIFKJWXTIj9SZR926i9L_TXJs,191
3
+ proportion_calculator/cli.py,sha256=dGpxT9_aPLOADk5lSZ6JVCwSm8FleKYCMbZ7tkNt0OA,2534
4
+ prop_cli-1.0.0.dist-info/METADATA,sha256=HoZHlYh1Ox_BiVCIvIWv5TZ7ElicgkvMljmsZoZVQQ4,347
5
+ prop_cli-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ prop_cli-1.0.0.dist-info/entry_points.txt,sha256=vUgr-OdIh5PVkBzIU-UmECepG9MW_vQuvV27BO13rhs,60
7
+ prop_cli-1.0.0.dist-info/top_level.txt,sha256=qXlb9zLQuH5bA-OY6BDFPOybbhy6vRAnjuLK4Wl-QuI,22
8
+ prop_cli-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ prop-cli = proportion_calculator.cli:main
@@ -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 @@
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())