Program No.
Title: Creating a menu-driven Python program to perform arithmetic operations.
AIM:
To write a menu-driven Python program to perform arithmetic operations (+, –, ×, ÷)
based on the user's choice.
SOURCE CODE:
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
opt = int(input("Enter your choice: "))
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
if opt == 1:
c=a+b
print("The addition of two numbers is:", c)
elif opt == 2:
c=a-b
print("The subtraction of two numbers is:", c)
elif opt == 3:
c=a*b
print("The multiplication of two numbers is:", c)
elif opt == 4:
if b == 0:
print("Error! Division by zero is not allowed.")
else:
c=a/b
print("The division of two numbers is:", c)
else:
print("Invalid option!")
SAMPLE OUTPUT 1:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter your choice: 1
Enter the first number: 15
Enter the second number: 10
The addition of two numbers is: 25.0
SAMPLE OUTPUT 2:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter your choice: 4
Enter the first number: 8
Enter the second number: 0
Error! Division by zero is not allowed.
RESULT:
Thus, the above Python program is executed successfully and the output is verified. ✅