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

Q2A

The document contains a simple calculator program that performs addition, subtraction, multiplication, and division. It presents a menu for user interaction and processes user input to perform the selected operation until the user chooses to exit. The program handles division by zero by returning None in that case.

Uploaded by

mauuudhoke07
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)
4 views2 pages

Q2A

The document contains a simple calculator program that performs addition, subtraction, multiplication, and division. It presents a menu for user interaction and processes user input to perform the selected operation until the user chooses to exit. The program handles division by zero by returning None in that case.

Uploaded by

mauuudhoke07
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/ 2

def add(a, b):

return a + b

def subtract(a, b):


return a - b

def multiply(a, b):


return a * b

def divide(a, b):


if b != 0:
return a / b
else:
return

while True:
print("\nMenu:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")

choice = input("Enter your choice (1-5): ")

if choice == '5':
print("Exiting program...")
break

a = int(input("Enter first number: "))


b= int(input("Enter second number: "))

if choice == '1':
print("Result:", add(a,b))
elif choice == '2':
print("Result:", subtract(a,b))
elif choice == '3':
print("Result:", multiply(a,b))
elif choice == '4':
print("Result:", divide(a,b))
else:
print("Invalid choice")

*********OUTPUT**********

Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 1
Enter first number: 12
Enter second number: 13
Result: 25
Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 2
Enter first number: 34
Enter second number: 45
Result: -11

Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 5
Exiting program...

You might also like