#prints the options: Add, Subtract, Multiply, and Divide
print("Calculator")
print("1 = Add")
print("2 = Subtract")
print("3 = Multiply")
print("4 = Divide")
#Asks you what operation you want to do.
choice = int(input("Choose (1,2,3,4): "))
while choice not in [1, 2, 3, 4]:
#if you dont choose any, then it will ask you to choose again.
print("Invalid choice. Please choose a number from 1 to 4.")
choice = int(input("Choose (1,2,3,4): "))
#It will ask you for two numbers, and then based off of what you chose, it will do the operation.
if choice == 1:
num1 = float(input("What's your first number? "))
num2 = float(input("What's your second number? "))
print(num1 + num2)
elif choice == 2:
num1 = float(input("What's your first number? "))
num2 = float(input("What's your second number? "))
print(num1 - num2)
elif choice == 3:
num1 = float(input("What's your first number? "))
num2 = float(input("What's your second number? "))
print(num1 * num2)
elif choice == 4:
num1 = float(input("What's your first number? "))
num2 = float(input("What's your second number? "))
if num2 == 0:
print("Error: Cannot divide by zero")
else:
print(num1 / num2)
Calculator
1 = Add
2 = Subtract
3 = Multiply
4 = Divide
11.0