0% found this document useful (0 votes)
6 views2 pages

Python Menu-Driven Calculator Program

The document outlines a menu-driven Python program that performs basic arithmetic operations: addition, subtraction, multiplication, and division based on user input. It includes source code and sample outputs demonstrating the program's functionality, including error handling for division by zero. The program successfully executes and provides the expected results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Python Menu-Driven Calculator Program

The document outlines a menu-driven Python program that performs basic arithmetic operations: addition, subtraction, multiplication, and division based on user input. It includes source code and sample outputs demonstrating the program's functionality, including error handling for division by zero. The program successfully executes and provides the expected results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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. ✅

You might also like