-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (26 loc) · 748 Bytes
/
main.py
File metadata and controls
30 lines (26 loc) · 748 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
def calculate(num1, op, num2):
if op == "+":
return num1 + num2
elif op == "-":
return num1 - num2
elif op == "*":
return num1 * num2
elif op == "/":
if num2 == 0:
return "Error: Division by zero"
return num1 / num2
else:
return "Invalid operation"
while True:
try:
num1 = float(input("Enter first number: "))
op = input("Enter operation (+, -, *, /): ")
num2 = float(input("Enter second number: "))
except:
print("Invalid input. Try again.")
continue
result = calculate(num1, op, num2)
print("Result:", result)
again = input("Do you want to continue? (y/n): ")
if again.lower() != "y":
break