From ab8ffb61d14352d80b4a2d1c078b296df3d3c178 Mon Sep 17 00:00:00 2001 From: Varun JP <92174003+Varun-JP@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:39:02 +0530 Subject: [PATCH] Create Calculator.py Simple Calculator using python --- pycalci.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pycalci.py diff --git a/pycalci.py b/pycalci.py new file mode 100644 index 0000000..4d2e093 --- /dev/null +++ b/pycalci.py @@ -0,0 +1,51 @@ +def add(num1, num2): + return num1 + num2 + +def subtract(num1, num2): + return num1 - num2 + +def multiply(num1, num2): + return num1 * num2 + +def divide(num1, num2): + return num1 / num2 + +loop=1 +while loop==1: + print("Please select operation -\n" \ + "1. Add\n"\ + "2. Subtract\n" \ + "3. Multiply\n" \ + "4. Divide\n" \ + "5. Exit") + + try: + select = int(input("--> ")) + if(select==5): + loop=0 + elif(select>5) : + print("HEYYY,read the damn instructions!\n Do you want to try again?") + else: + number1 = int(input("Enter first number: ")) + number2 = int(input("Enter second number:")) + + #after selection + if (select == 1): + print(number1, "+", number2, "=",add(number1, number2)) + + elif (select == 2): + print(number1, "-", number2, "=",subtract(number1, number2)) + + elif (select == 3): + print(number1, "*", number2, "=",multiply(number1, number2)) + + elif (select == 4): + + if (number2 == 0): + print("[Sorry, the scientist are still figuring out that one]\n") + else: + print(number1, "/", number2, "=",divide(number1, number2)) + + + except: + print("[error, this is IMPOSSIBLE!\n Do you want to try again?]\n")