-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.py
More file actions
28 lines (21 loc) · 661 Bytes
/
calc.py
File metadata and controls
28 lines (21 loc) · 661 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
#Simple Python calculator
operator = input("Enter one operator (+, -, *, /): ")
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
try:
if operator == "+" :
result = num1 + num2
print(result)
elif operator == "-" :
result = num1 - num2
print(result)
elif operator == "*" :
result = num1 * num2
print(result)
elif operator == "/" :
result = num1 / num2
print(round(result, 3)) #rounding up the result to 3dp
else :
print(f'{operator} is not a valid operator')
except ZeroDivisionError as f:
print(f"error {f}")