From d801e5e44acdfdd35558af06b8afc4ff7a4e4b1b Mon Sep 17 00:00:00 2001 From: kamalnathDhekwar <123158118+kamalnathdhekwar@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:47:16 +0530 Subject: [PATCH] my new nada program --- .../client_code/run_my_first_program.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/quickstart/client_code/run_my_first_program.py b/quickstart/client_code/run_my_first_program.py index e69de29b..72f720ac 100644 --- a/quickstart/client_code/run_my_first_program.py +++ b/quickstart/client_code/run_my_first_program.py @@ -0,0 +1,42 @@ +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 "Error! Division by zero." + +def calculator(): + print("Select operation:") + print("1. Addition") + print("2. Subtraction") + print("3. Multiplication") + print("4. Division") + + choice = input("Enter choice (1/2/3/4): ") + + if choice in ('1', '2', '3', '4'): + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + operations = { + '1': add, + '2': subtract, + '3': multiply, + '4': divide + } + + result = operations[choice](num1, num2) + print(f"The result is: {result}") + else: + print("Invalid input") + +if __name__ == "__main__": + calculator()