-
Notifications
You must be signed in to change notification settings - Fork 8
/
calculator.py
29 lines (26 loc) · 969 Bytes
/
calculator.py
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
while True:
print("Options:")
print("Enter 'add' for addition")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input in ("add", "subtract", "multiply", "divide"):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if user_input == "add":
print("Result:", num1 + num2)
elif user_input == "subtract":
print("Result:", num1 - num2)
elif user_input == "multiply":
print("Result:", num1 * num2)
elif user_input == "divide":
if num2 == 0:
print("Cannot divide by zero")
else:
print("Result:", num1 / num2)
else:
print("Invalid input. Please try again.")