12-CS-LAB PGRM1.docx
12-CS-LAB PGRM1.docx
No:1
DATE:
Arithmetic operations
AIM:
To write a menu driven python program to perform Arithmetic operations
based on the user’s choice.
SOURCE CODE:
def addition(a, b):
sum = a + b
print(a, "+", b, "=", sum)
def subtraction(a, b):
difference = a - b
print(a, "-", b, "=", difference)
def multiplication(a, b):
product = a * b
print(a, "*", b, "=", product)
def divide(a, b):
quotient = a / b
remainder = a % b
print("Quotient of", a, "/", b, "=", quotient)
print("Remainder of", a, "%", b, "=", remainder)
print("WELCOME TO CALCULATOR")
while True:
print("\nChoose the operation to perform:")
print("1. Addition of two numbers")
print("2. Subtraction of two numbers")
print("3. Multiplication of two numbers")
print("4. Division of two numbers")
print("5. Exit")
choice = int(input("\nEnter your Choice: "))
if choice == 1:
print("\nAddition of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
addition(a,b)
elif choice == 2:
print("\nSubtraction of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
subtraction(a,b)
elif choice == 3:
print("\nMultiplication of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
multiplication(a,b)
elif choice == 4:
print("\nDivision of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
divide(a,b)
elif choice == 5:
print("Thank You! Bye.")
break
else:
print("Invalid Input! Please, try again.")
SAMPLE OUTPUT
WELCOME TO CALCULATOR
Choose the operation to perform:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit
Enter your Choice: 1
Addition of two numbers
Enter the first number: 5
Enter the second number: 5
5 + 5 = 10
Choose the operation to perform:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit
Enter your Choice: 2
Subtraction of two numbers
Enter the first number: 5
Enter the second number: 5
5-5=0
Choose the operation to perform:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit
Enter your Choice: 3
Multiplication of two numbers
Enter the first number: 5
Enter the second number: 5
5 * 5 = 25
Choose the operation to perform:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit
Enter your Choice: 4
Division of two numbers
Enter the first number: 25
Enter the second number: 5
Quotient of 25 / 5 = 5.0
Remainder of 25 % 5 = 0
Choose the operation to perform:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit
Enter your Choice: 5
Thank You! Bye.
Result:
The above output has been verified in the terminal.