-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCal.py
More file actions
30 lines (26 loc) · 837 Bytes
/
Copy pathCal.py
File metadata and controls
30 lines (26 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Read two numbers from the user
n = int(input("Enter the first number: "))
m = int(input("Enter the second number: "))
# Function to perform calculation based on user choice
def cal(a, b):
# Display menu for operations
print("Choose operation: (1-Addition/2-Subtraction/3-Multiplication/4-Division)")
# Read user's choice
choice = int(input("Enter your choice: "))
# Perform operation based on choice
if choice == 1:
return a + b
elif choice == 2:
return a - b
elif choice == 3:
return a * b
elif choice == 4:
if b != 0:
return a / b
else:
return "Error: Division by zero"
else:
return "Wrong input"
# Call the function and print the result
result = cal(n, m)
print("Result:", result)