From 42f36c2d31c878da7b2f0c1d3b620581187b8e2d Mon Sep 17 00:00:00 2001 From: "lev.karpov" Date: Tue, 31 Mar 2026 19:02:31 +0000 Subject: [PATCH] Add basic Python calculator --- main.py | 29 +++++++++++++++++++++++++++++ requirements.txt | 0 2 files changed, 29 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..0c05d9c --- /dev/null +++ b/main.py @@ -0,0 +1,29 @@ +def calculate(a, b, operation): + if operation == "+": + return a + b + if operation == "-": + return a - b + if operation == "*": + return a * b + if operation == "/": + if b == 0: + raise ValueError("Division by zero is not allowed") + return a / b + raise ValueError(f"Unsupported operation: {operation}") + + +def main(): + print("Simple Python Calculator") + first = float(input("Enter the first number: ")) + operation = input("Choose operation (+, -, *, /): ").strip() + second = float(input("Enter the second number: ")) + + try: + result = calculate(first, second, operation) + print(f"Result: {result}") + except ValueError as error: + print(f"Error: {error}") + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29