-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.py
More file actions
45 lines (34 loc) · 786 Bytes
/
operations.py
File metadata and controls
45 lines (34 loc) · 786 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
38
39
40
41
42
43
44
45
import math
def add(a, b):
return a+b
def subtract(a,b):
return a-b
def multiply(a,b):
return a*b
def divide(a,b):
if b == 0:
raise ZeroDivisionError("Cannot divide by 0")
return a/b
def power(a,b):
return math.pow(a,b)
def uminus(a, b):
return a * -1.0
def sine(a, b):
return math.sin(a)
def cosine(a, b):
return math.cos(a)
def tangent(a, b):
if cosine(a, b) == 0:
raise ValueError("Tangent value undefined")
else:
return math.tan(a)
def fact(a, b):
if a < 0:
raise ValueError("Cannot carry out the factorial of a negative number.")
else:
if (a % 1 == 0):
return math.factorial(int(a))
else:
return math.gamma(a)
if __name__ == "__main__":
pass