Test 14

You might also like

You are on page 1of 1

def get_choice(): print("your options are:" ) print print("1) print("2) print("3) print("4) print("5) print Addition") Subtraction") Multiplication")

Division") Quit calculator.py")

choice = input("Choose your option: ") try: choice = int(choice) except ValueError: choice = 0 return choice def main(): print("Welcome to calculator program") while True: choice = get_choice() if choice == 5: return if choice == 0: print("Not a valid input, please reconsider.") print continue try: op1 = int(input("Enter first operand : ")) op2 = int(input("Enter second operand : ")) except ValueError: print("Invalid operand") continue if choice == 1: print(op1, "+", op2, "=", op1 + op2) elif choice == 2: print(op1, "-", op2, "=", op1 - op2) elif choice == 3: print(op1, "*", op2, "=", op1 * op2 ) elif choice == 4: if op2 == 0: print("Cannot divide by zero") else: print(op1, "/", op2, "=", op1 / op2) if __name__ == '__main__': try: main() except (EOFError, KeyboardInterrupt): pass print print("Thank you for using calculator py!")

You might also like