chapter 2.1 calculator project setup

This commit is contained in:
2025-07-31 16:31:52 +02:00
parent f9a9c430e8
commit 3fb2ef23bf
4 changed files with 155 additions and 0 deletions

22
calculator/main.py Normal file
View File

@@ -0,0 +1,22 @@
import sys
from pkg.calculator import Calculator
from pkg.render import render
def main():
calculator = Calculator()
if len(sys.argv) <= 1:
print("Calculator App")
print("Usage: python main.py \"<expression>\"")
print("Example: python main.py \"3 + 5\"")
return
expression = " ".join(sys.argv[1:])
try:
result = calculator.evaluate(expression)
to_print = render(expression, result)
print(to_print)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()