0% found this document useful (0 votes)
9 views3 pages

12-CS-LAB PGRM1.docx

The document outlines a menu-driven Python program for performing basic arithmetic operations: addition, subtraction, multiplication, and division based on user input. It includes function definitions for each operation and a loop that prompts the user to select an operation until they choose to exit. Sample output demonstrates the program's functionality and confirms its successful execution in a terminal.

Uploaded by

dhanunathi2008
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)
9 views3 pages

12-CS-LAB PGRM1.docx

The document outlines a menu-driven Python program for performing basic arithmetic operations: addition, subtraction, multiplication, and division based on user input. It includes function definitions for each operation and a loop that prompts the user to select an operation until they choose to exit. Sample output demonstrates the program's functionality and confirms its successful execution in a terminal.

Uploaded by

dhanunathi2008
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
You are on page 1/ 3

P.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy