-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.py
53 lines (50 loc) · 1.16 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
46
47
48
49
50
51
52
53
import math
op = input()
if op == "sqrt" or op == "sin" or op == "cos" or op == "tan" or op == "fct":
a = float(input())
else:
a = float(input())
b = float(input())
if op == "+":
result = a+b
elif op == "-":
result = a-b
elif op == "*":
result = a*b
elif op == "/":
if b == 0:
result = "Cannot divide by zero!"
else:
result = a/b
elif op == "^":
result = a**b
elif op == "log":
result = math.log(a, b)
elif op == "sqrt":
result = math.sqrt(a)
elif op == "sin":
d = a*math.pi/180
result = math.sin(d)
elif op == "cos":
d = a*math.pi/180
result = math.cos(d)
elif op == "tan":
d = a*math.pi/180
result = math.tan(d)
elif op == "cot":
d = a*math.pi/180
result = 1/math.tan(d)
elif op == "fct":
factorial = 1
if a < 0:
print("Sorry, factorial does not exist for negative numbers")
elif a == 0:
print("The factorial of 0 is 1")
else:
a = int(a)
for i in range(1, a + 1):
factorial = factorial*i
result = factorial
else:
result = "Error! operator not found"
print(result)