-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathultimatecalculator.py
More file actions
250 lines (207 loc) · 7.35 KB
/
ultimatecalculator.py
File metadata and controls
250 lines (207 loc) · 7.35 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import math
from image import art
def calculate_addition(num_1, num_2):
value = num_1 + num_2
print(f"{num_1} + {num_2} = {value}")
def calculate_subtraction(num_1, num_2):
value = num_1 - num_2
print(f"{num_1} - {num_2} = {value}")
def calculate_multiplication(num_1, num_2):
value = num_1 * num_2
print(f"{num_1} * {num_2} = {value}")
def calculate_division(num_1, num_2):
value = num_1 / num_2
print(f"{num_1} / {num_2} = {value}")
def calculate_logarithm(base, num):
value = math.log(num, base)
print(f"log of {num} with base {base} = {value}")
def calculate_exponentiation(base, exponent):
value = math.pow(base, exponent)
print(f"{base} to the power {exponent} = {value}")
def calculate_trigonometry(_type_, num):
if _type_ == 1:
value = math.sin(num)
print(f"{_type_} {num} = {value}")
elif _type_ == 2:
value = math.tan(num)
print(f"{_type_} {num} = {value}")
elif _type_ == 3:
value = math.cos(num)
print(f"{_type_} {num} = {value}")
elif _type_ == 4:
value = math.acos(num)
print(f"{_type_} {num} = {value}")
elif _type_ == 5:
value = math.asin(num)
print(f"{_type_} {num} = {value}")
elif _type_ == 6:
value = math.atan(num)
print(f"{_type_} {num} = {value}")
else:
print("The type isn't correct.")
def calculate_area_circle(radius):
area = math.pi * radius ** 2
print(f"Area of circle of radius {radius} is {area} unit square")
def calculate_area_rectangle(length, breadth):
area = length * breadth
print(f"Area of rectangle of length {length} and breadth {breadth} is {area} unit square")
def calculate_area_triangle(base, height):
area = 0.5 * base * height
print(f"Area of triangle of base {base} and height {height} is {area} unit square")
def calculate_area_square(side):
area = side * side
print(f"Area of square of side {side} is {area} unit square")
def calculate_area_parallelogram(base, height):
area = base * height
print(f"Area of parallelogram of base {base} and height {height} is {area} unit square")
def main():
while True:
try:
print(art)
print("Welcome to the mathematical equation solver!")
print("Here are the equations that I can solve:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exponentiation")
print("6. Logarithm")
print("7. Trigonometry")
print("8. Area of Shapes")
print("Quit - Ctrl + C")
print()
choice = int(input("Please select an equation to solve: "))
if _type_ in [1,2,3,4,5,6,7,8]:
break
else:
print("Invalid input")
except ValueError:
print("Invalid input")
if choice < 5:
while True:
try:
num_1 = float(input("Enter the first number: "))
break
except ValueError:
print("Invalid input")
while True:
try:
num_2 = float(input("Enter the second number: "))
break
except ValueError:
print("Invalid input")
if choice == 1:
calculate_addition(num_1)
elif choice == 2:
calculate_subtraction(num_1)
elif choice == 3:
calculate_multiplication(num_1)
elif choice == 4:
calculate_division(num_1)
elif choice == 5:
while True:
try:
base = float(input("Enter the base number: "))
break
except ValueError:
print("Invalid input")
while True:
try:
num = float(input("Enter the number: "))
break
except ValueError:
print("Invalid input")
calculate_exponentiation(base, num)
elif choice == 6:
while True:
try:
base = float(input("Enter the base number: "))
break
except ValueError:
print("Invalid input")
while True:
try:
exponent = float(input("Enter the exponent number: "))
break
except ValueError:
print("Invalid input")
calculate_logarithm(base, exponent)
elif choice == 7:
while True:
try:
print("What trigonometry function do you want to use:")
print("1. sin")
print("2. cos")
print("3. cosine")
print("4. tan")
print("5. cot")
print("6. sec")
print()
_type_ = int(input("Please select a function to solve: ")).lower()
if _type_ in [1,2,3,4,5,6]:
break
else:
print("Invalid input")
except ValueError:
print("Invalid input")
while True:
try:
exponent = float(input("Enter the Number: "))
break
except ValueError:
print("Invalid input")
calculate_trigonometry(_type_, num)
elif choice == 8:
# Areas of different shapes
while True:
try:
print("What is the shape:")
print("1. Circle")
print("2. Rectangle")
print("3. Triangle")
print("4. Square")
print("5. Parallelogram")
print()
shape = int(input("Please enter the number of shape whose area you want to find: "))
if _type_ in [1,2,3,4,5]:
break
else:
print("Invalid input")
except ValueError:
print("Invalid input")
if shape == 1:
radius = float(input("Enter the radius of the circle: "))
print()
calculate_area_circle(radius)
elif shape == 2:
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
print()
calculate_area_rectangle(length, breadth)
elif shape == 3:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
print()
calculate_area_triangle(base, height)
elif shape == 4:
side = float(input("Enter the side of the square: "))
print()
calculate_area_square(side)
elif shape == 5:
base = float(input("Enter the base of the parallelogram: "))
height = float(input("Enter the height of the parallelogram: "))
print()
calculate_area_parallelogram(base, height)
run = True
while run:
main()
while True:
ask = input('Do you want to continue(Y/N): ')
if ask.lower() == 'n':
print("Bye! Have a great time!")
run = False
break
elif ask.lower() == 'y':
break
else:
print("Invalid input")