# Calculator in Python Machine Problem in Python

1. Create a calculator app
2. The user will choose between the 4 math operations (Add, Subtract, Multiply and Divide)
3. The application will ask for 2 numbers
4. Display the result
5. The application will ask again if the user wants to try again
6. Use the appropriate Exception (ex: Invalid input such as text and zero division)

Program Listing

``````# mod5_act2.py
# Author : Jake R. Pomperada

def calculator():
validMenuOptions = ["+", "-", "*", "/", "e"]
while True:

print("[-] Error: Invalid Input!")
print("[+] Program Terminated!")
break
else:
# Asking user to enter numbers
try:
firstNumber = float(input("Enter 1st Number: "))
secondNumber = float(input("Enter 2nd Number: "))

result = 0

# Checking each possibility and storing the output in 'result' variable
result = firstNumber + secondNumber
result = firstNumber - secondNumber
result = firstNumber * secondNumber
if secondNumber == 0:
print("[-] Error: Cannot divide by zero")
else:
result = firstNumber / secondNumber
except:
print("[-] Error: Invalid Input! Only numerical input is allowed.")

print("----------------------------")
print("Enter (-) for Subtraction")
print("Enter (*) for Multiplication")
print("Enter (/) for Division")
print("Enter (e) to Exit")
print("----------------------------")

if __name__ == "__main__":
calculator()``````