From 776a0295f025f5919b5cbabc0a3ae29da1dc813a Mon Sep 17 00:00:00 2001 From: Vedansh Agarwal Date: Fri, 2 Oct 2020 22:38:32 +0530 Subject: [PATCH] Basic calculator --- Basics/calculator.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Basics/calculator.py diff --git a/Basics/calculator.py b/Basics/calculator.py new file mode 100644 index 00000000..ebeb407f --- /dev/null +++ b/Basics/calculator.py @@ -0,0 +1,24 @@ +def operate(a, b, choice): + #creating a dictionary (equivalent to switch-case statements) + switcher = { + 1: a+b, + 2: a-b, + 3: a*b, + 4: a/b, + 5: a**b, + 6: a%b + } + + return switcher.get(choice, "Invalid choice") + +if __name__ == '__main__': + #Menu - Available choices + print("1. Addition\n2. Substraction\n3. Multiplication\n4. Division\n5. Exponentiation\n6. Modulo\n") + + firstNum = float(input('Enter first number : ')) + secondNum = float(input('Enter second number : ')) + choice = int(input('Enter choice from the above list : ')) + + print(operate(firstNum, secondNum, choice)) + +