-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcal.py
More file actions
31 lines (28 loc) · 998 Bytes
/
Copy pathcal.py
File metadata and controls
31 lines (28 loc) · 998 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
31
while True:
print("Options:")
print("Enter 'add' for addition")
print("Enter 'sub' for subtraction")
print("Enter 'mul' for multiplication")
print("Enter 'div' for division")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input in ("add", "sub", "mul", "div"):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if user_input == "add":
print(f"Result: {num1 + num2}")
elif user_input == "sub":
print(f"Result: {num1 - num2}")
elif user_input == "mul":
print(f"Result: {num1 * num2}")
elif user_input == "div":
if num2 != 0:
print(f"Result: {num1 / num2}")
else:
print("Cannot divide by zero.")
else:
print("Invalid input")
else:
print("Invalid input")