Loading...
Join Community
Get in touch
Shushant
January 16, 2024
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y != 0:
return x / y
else:
return "Cannot divide by zero"
while True:
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")
choice = input("Enter choice (1/2/3/4/5): ")
if choice == '5':
print("Calculator exiting. Goodbye!")
break
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print("Add =" , num1 + num2)
elif choice == '2':
print("Subtract =" , num1 - num2)
elif choice == '3':
print("multiply =" , num1 * num2)
elif choice == '4':
print("divide =" , num1 / num2)
else:
print("Invalid input. Please enter a valid number (1/2/3/4/5).")