-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
137 lines (103 loc) · 3.33 KB
/
functions.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
__doc__ = "Implementation of mathematical functions"
from helper import get_float_input
from helper import get_int_input
from math import sin, cos, tan, asin, acos, radians, degrees, atan
class Arithmetic:
def add(self):
sum_ = 0
while True:
num = get_float_input()
if num == 0:
break
else:
sum_ += float(num)
return sum_
def sub(self):
num1 = get_float_input()
num2 = get_float_input()
return num1 - num2
def mul(self):
mul_ = 1
while True:
num = get_float_input()
if num == 1.0:
break
mul_ *= num
return round(mul_, 2)
def div(self):
num1 = get_float_input(msg="Enter the numerator: ")
num2 = get_float_input(msg="Enter the divisor: ")
return round(num1 / num2, 4)
class Polynomial:
def get_quad_roots(self):
print("Enter in the form: ax²+bx+c")
a = get_float_input(msg="a? : ")
b = get_float_input(msg="b? : ")
c = get_float_input(msg="c? : ")
det_ = (b**2) - (4*a*c)
if det_ < 0:
return "No real root"
elif det_ == 0:
root = (-b + (det_**0.5)) / (2*a)
return f"The root of the equation is {root}"
else:
root1 = (-b + (det_**0.5)) / (2*a)
root2 = (-b - (det_**0.5)) / (2*a)
return f"The roots of the equation are {root1} and {root2}"
class NumberProperties:
def is_even(self):
num = get_int_input()
return num % 2 == 0
def is_prime(self):
num = get_int_input()
if num <= 1:
return False
for i in range(2, int(num**0.5)+1):
if num % i == 0:
return False
return True
def factorial(self):
print("Enter a number to see its factorial")
value = 1
num = get_int_input()
if num < 0:
return "There is no factorial for negative numbers"
for x in range(1, num+1):
if num == 1 | num == 0:
break
else:
value *= x
return f"The factorial is {value}"
class Trignometry:
def __init__(self, mode="radians") -> None:
self.mode = mode
def find_sin(self):
num = get_float_input()
if self.mode == "degrees":
return round(sin(radians(num)), 4)
return round(sin(num), 4)
def find_cos(self):
num = get_float_input()
if self.mode == "degrees":
return round(cos(radians(num)), 4)
return round(cos(num), 4)
def find_tan(self):
num = get_float_input()
if self.mode == "degrees":
return round(tan(radians(num)), 4)
return round(tan(num), 4)
def find_sin_inverse(self):
num = get_float_input()
if self.mode == "degrees":
return round(degrees(asin(num)), 4)
return round(asin(num), 4)
def find_cos_inverse(self):
num = get_float_input()
if self.mode == "degrees":
return round(degrees(acos(num)), 4)
return round(acos(num), 4)
def find_tan_inverse(self):
num = get_float_input()
if self.mode == "degrees":
return round(degrees(atan(num)), 4)
return round(atan(num), 4)