From 15dc42e602f5f01c64078e563cf416a04b51fe51 Mon Sep 17 00:00:00 2001 From: Jan Karban Date: Tue, 10 Dec 2024 14:30:12 +0100 Subject: [PATCH] calculator --- Dockerfile | 6 ++++++ app.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf9d246 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.9-slim + +WORKDIR /app +COPY . /app + +CMD ["python", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..a640690 --- /dev/null +++ b/app.py @@ -0,0 +1,34 @@ +def add(a, b): + return a + b + +def subtract(a, b): + return a - b + +def multiply(a, b): + return a * b + +def divide(a, b): + if b != 0: + return a / b + else: + return "Division by zero error" + +def main(): + print("Simple Python Calculator") + a = float(input("Enter first number: ")) + b = float(input("Enter second number: ")) + operation = input("Enter operation (+, -, *, /): ") + + if operation == '+': + print(f"Result: {add(a, b)}") + elif operation == '-': + print(f"Result: {subtract(a, b)}") + elif operation == '*': + print(f"Result: {multiply(a, b)}") + elif operation == '/': + print(f"Result: {divide(a, b)}") + else: + print("Invalid operation") + +if __name__ == "__main__": + main()