-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.py
45 lines (38 loc) · 1.06 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import math
while True:
def addition(x, y):
ans = x + y
return ans
def subtraction(x, y):
ans = x - y
return ans
def multiplication(x, y):
ans = x * y
return ans
def division(x, y):
try:
ans = x / y
return ans
except ZeroDivisionError:
print("Do not divide by zero!!")
except:
print("Unknown Error")
def pythag(x, y):
ans = (x ** 2) + (y ** 2)
ans = math.sqrt(ans)
ans = round(ans, 3)
return ans
func = input("What operator do you want to use?\nA. Addition\nB. Subtraction\nC. Multiplication\nD. Division\nE. Pythagoreans Theorem\n")
func = func.upper()
x = float(input("What is value A? "))
y = float(input("What is value B? "))
if func == "A":
print(addition(x, y))
elif func == "B":
print(subtraction(x, y))
elif func == "C":
print(multiplication(x, y))
elif func == "D":
print(division(x, y))
elif func == "E":
print(pythag(x, y))