-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-calc.py
More file actions
37 lines (28 loc) · 758 Bytes
/
11-calc.py
File metadata and controls
37 lines (28 loc) · 758 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
32
33
34
35
36
37
#!/usr/bin/env python3
def operate(n1, n2, operation):
n1 = int(n1)
n2 = int(n2)
if operation == "+":
result = n1 + n2
elif operation == "-":
result = n1 - n2
elif operation == "*":
result = n1 * n2
elif operation == "/":
if n2 == 0:
raise Exception("Can not divide by zero")
result = n1 / n2
else:
raise Exception("Unknown operation")
return result
def main():
n1 = input("First number: ")
n2 = input("Second number: ")
operation = input("Operation (+,-,*,/): ")
try:
result = operate(n1, n2, operation)
print(result)
except Exception as e:
print(e)
if __name__ == "__main__":
main()