PHYTHON PROGRAM
# This program does addition and subtraction using functions and a loop
# Function to add two numbers
def add(x, y):
return x + y
# Function to subtract two numbers
def subtract(x, y):
return x - y
# Main program
while True:
print("\n===== Simple Calculator =====")
print("1. Add two numbers")
print("2. Subtract two numbers")
print("3. Exit")
choice = input("Enter your choice (1/2/3): ")
if choice == '1':
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
result = add(num1, num2)
print("The sum is:", result)
elif choice == '2':
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
result = subtract(num1, num2)
print("The difference is:", result)
elif choice == '3':
print("Thank you for using the calculator!")
break
else:print("Invalid choice. Please choose 1, 2, or 3.")