-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheng.py
455 lines (442 loc) · 15.6 KB
/
eng.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
# Import libraries
import math
import sympy
import sympy.abc
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import os
import scipy
import time
# import from libraries
from sympy import *
from math import sin, cos, tan
from os import *
from sympy.abc import symbols, x, y, theta
# Delay before cleaning
delay = 10 # time of delay in seconds;
# For saving graphic in file
def save(name='', fmt='png'):
pwd = os.getcwd()
iPath = './'.format(fmt)
if not os.path.exists(iPath):
os.mkdir(iPath)
os.chdir(iPath)
plt.savefig('{}.{}'.format(name, fmt), fmt='png')
os.chdir(pwd)
# Cleaning screen
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
# Begin
value = None
while value != 0:
# Request for selection of operations
print (' ----------------------------')
value = int(input(" Select a category: \n \n 0) Exit \n 1) Simple actions \n 2) Trigonometry \n 3) Geometry \n 4) Other \n 5) Higher Mathematics \n 6) Electricity \n ---------------------------- \n "))
# Exit
if (value == 0):
print('-' * 28 + '\n Thanks for using!\n' + '-' * 28)
##############################################################################################################################
# Simple actions
elif (value == 1):
value = int(input(
"\n 11) Addiction \n 21) Subtraction \n 31) Division \n 41) Multiplication \n \n"))
# Addiction
if (value == 11):
print ("")
x = float(input(" Enter the first number: "))
print (' ----------------------------')
y = float(input(" Enter the second number: "))
print (' ----------------------------')
print (' {} + {}'.format(x, y))
print (' ----------------------------')
print (x + y)
time.sleep(delay)
cls()
# Subtraction
elif (value == 21):
print ("")
x = float(input(" Enter the first number: "))
print (' ----------------------------')
y = float(input(" Enter the second number: "))
print (' ----------------------------')
print (' {} - {}'.format(x, y))
print (' ----------------------------')
print (x - y)
time.sleep(delay)
cls()
# Division
elif (value == 31):
print ("")
x = float(input(" Enter the first number: "))
print (' ----------------------------')
y = float(input(" Enter the second number: "))
print (' ----------------------------')
print (' {} / {}'.format(x, y))
print (' ----------------------------')
print (x / y)
time.sleep(delay)
cls()
# Multiplication
elif (value == 41):
print ("")
x = float(input(" Enter the first number: "))
print (' ----------------------------')
y = float(input(" Enter the second number: "))
print (' ----------------------------')
print (' {} * {}'.format(x, y))
print (' ----------------------------')
print (x * y)
time.sleep(delay)
cls()
else:
print("I don't know what you write, try again")
##############################################################################################################################
# Trigonometry
elif (value == 2):
value = int(input(
"\n 12) Sine \n 22) Cosine \n 32) Tangent \n 42) Cotangent \n 52) Secant \n 62) Cosecant \n \n"))
# Sine
if (value == 12):
print ("")
x = float(input(" Enter a number: "))
print (' ----------------------------')
print (sin(x))
time.sleep(delay)
cls()
# Cosine
elif (value == 22):
print ("")
x = float(input(" Enter a number: "))
print (' ----------------------------')
print (cos(x))
time.sleep(delay)
cls()
# Tangent
elif (value == 32):
print ("")
x = float(input(" Enter a number: "))
print (' ----------------------------')
print (tan(x))
time.sleep(delay)
cls()
# Cotangent
elif (value == 42):
print ("")
x = float(input(" Enter a number: "))
tan = tan(x)
print (' ----------------------------')
print (1 / tan)
time.sleep(delay)
cls()
# Secant
elif (value == 52):
print ("")
x = float(input(" Enter a number: "))
sin = sin(x)
print (' ----------------------------')
print (1 / sin)
time.sleep(delay)
cls()
# Cosecant
elif (value == 62):
print ("")
x = float(input(" Enter a number: "))
cos = cos(x)
print (' ----------------------------')
print (1 / cos)
time.sleep(delay)
cls()
else:
print("I don't know what you write, try again")
##############################################################################################################################
# Geometry
elif (value == 3):
value = int(input("\n 13) Hypotenuse \n 23) Сathetus \n 33) Area of a Rectangle \n 43) Area of a Triangle \n 53) Area of a Right Triangle-Angled \n 63) Area of a Equilateral Triangle \n 73) Area of a Rhombus \n 83) Area of a Parallelogram \n 93) Area of a Trapezoid \n \n"))
# Hypotenuse
if (value == 13):
print ("")
katet_one = float(input(" Enter the first сathetus: "))
katet_two = float(input(" Enter the second сathetus: "))
gipot = math.sqrt(katet_one**2 + katet_two**2)
print ("")
print (gipot)
time.sleep(delay)
cls()
# Сathetus
elif (value == 23):
print ("")
katet = float(input(" Enter the cathetus: "))
gipot = float(input(" Enter the hypotenuse : "))
res = math.sqrt(gipot**2 - katet**2)
print ("")
print (res)
time.sleep(delay)
cls()
# Area of a Rectangle
elif (value == 33):
print ("")
one = float(input(" Enter the first side: "))
two = float(input(" Enter the second side: "))
print ("")
print (two * one)
time.sleep(delay)
cls()
# Area of a Triangle
elif (value == 43):
print ("")
one = float(input(" Enter the side: "))
two = float(input(" Enter the height: "))
print ("")
print ((one * two) * 0.5)
time.sleep(delay)
cls()
# Area of a Right-Angled Ariangle
elif (value == 53):
print ("")
one = float(input(" Enter the first side: "))
two = float(input(" Enter the second side: "))
print ("")
print ((one * two) / 2)
time.sleep(delay)
cls()
# Area of a Equilateral Triangle
elif (value == 63):
print ("")
three = 3
one = float(input(" Enter the side: "))
print ("")
print ((one * math.sqrt(three)) / 4)
time.sleep(delay)
cls()
# Area of a Rhombus
elif (value == 73):
print ("")
one = float(input(" Enter the side: "))
two = float(input(" Enter the height: "))
print ("")
print (one * vis)
time.sleep(delay)
cls()
# Area of a Parallelogram
elif (value == 83):
print ("")
one = float(input(" Enter the first side: "))
two = float(input(" Enter the second side: "))
sine = float(input(" Enter an angle: "))
print ("")
print (one * two * math.sin(sine))
time.sleep(delay)
cls()
# Area of a Trapezoid
elif (value == 93):
print ("")
one = float(input(" Enter the first side: "))
two = float(input(" Enter the second side: "))
two = float(input(" Enter the height: "))
print ("")
print (((one + two) / 2) * vis)
time.sleep(delay)
cls()
else:
print("I don't know what you write, try again")
##############################################################################################################################
# Other
elif (value == 4):
value = int(input("\n 14) Graphic \n 24) Simplify \n \n "))
# Graphic
if (value == 14):
fig = plt.figure()
# Type of graphic
ax = fig.add_subplot(111)
rect = ax.patch
rect.set_facecolor('white')
rect.set_alpha(0)
print("")
# Limit by х
x = np.arange(-25, 25)
# Enter
y = input(" Enter the math.example: ")
plt.plot(x, y)
ax = plt.gca()
ax.plot(x, y, 'black')
xax = ax.xaxis
xlocs = xax.get_ticklocs()
xlabels = xax.get_ticklabels()
xlines = xax.get_ticklines()
ax.grid(True, which='major', color='y',
linewidth=2., linestyle='solid')
ax.grid(True, which='minor', color='k')
for label in ax.xaxis.get_ticklabels():
label.set_color('black')
label.set_rotation(0)
label.set_fontsize(14)
for line in ax.yaxis.get_ticklines():
line.set_color('black')
line.set_markersize(14)
line.set_markeredgewidth(3)
# Saving to the file
save('graphic', fmt='png')
for label in xlabels:
label.set_color('black')
label.set_rotation(0)
label.set_fontsize(12)
# Show a graphic
plt.show()
else:
print("I don't know what you write, try again")
# Simplify
if (value == 24):
print ("")
primer = raw_input(" Enter the math.example: ")
res = simplify(primer)
print ("")
sympy.pprint(res)
time.sleep(delay)
cls()
else:
print("I don't know what you write, try again")
##############################################################################################################################
# Higher Mathematics
elif (value == 5):
value = int(input("\n 15) Derivative \n 25) Integral \n 35) Limit (x->оо) \n 45) Limit (x->0) \n 55) Limit (x->1) \n 65) Limit (any number) \n 75) Definite Integral \n \n "))
# Derivative
if (value == 15):
print ("")
input_string = raw_input(' Enter the math.example: ')
print ("")
res = sum(sympy.diff(input_string, var) for var in [x, y])
sympy.pprint(res)
time.sleep(delay)
cls()
# Integral
elif (value == 25):
print ("")
x = Symbol("x")
y = Symbol("y")
input_string = input(' Enter the math.example: ')
print ("")
sympy.pprint(sympy.Integral(input_string, x))
print ("")
sympy.pprint(integrate(input_string, x))
time.sleep(delay)
cls()
# Definite Integral
elif (value == 75):
print ("")
x = Symbol("x")
y = Symbol("y")
input_string = input(' Enter the math.example: ')
ot = float(input(' From: '))
do = float(input(' To: '))
print ("")
sympy.pprint(sympy.Integral(input_string, (x, ot, do)))
print ("")
sympy.pprint(integrate(input_string, (x, ot, do)))
time.sleep(delay)
cls()
# Limit (x->оо)
elif (value == 35):
print ("")
value = input(' Enter the math.example: ')
print ("")
sympy.pprint(limit(value, x, oo))
time.sleep(delay)
cls()
# Limit (x->0)
elif (value == 45):
print ("")
value = input(' Enter the math.example: ')
print ("")
sympy.pprint(limit(value, x, 0))
time.sleep(delay)
cls()
# Limit (x->1)
elif (value == 55):
print ("")
value = input(' Enter the math.example: ')
print ("")
sympy.pprint(limit(value, x, 1))
time.sleep(delay)
cls()
# Limit (any numbers)
elif (value == 65):
print ("")
value = input(' Enter the math.example: ')
stremlenie = input(' What "x" tends to? ')
print ("")
sympy.pprint(limit(value, x, stremlenie))
time.sleep(delay)
cls()
else:
print("I don't know what you write, try again")
################################################################################################################################
elif (value == 6):
value = int(input(
"\n 16) Active Resistance \n 26) Inductive Resistance \n 36) Capacitance \n 46) Power \n 56) Current \n 66) Voltage \n \n "))
# Active Resistance
if (value == 16):
print ("")
u = float(input(" Voltage: "))
print (' ----------------------------')
i = float(input(" Current: "))
print ("")
print (u / i)
time.sleep(delay)
cls()
# Inductive Resistance
elif (value == 26):
print ("")
l = float(input(" Inductance: "))
print (' ----------------------------')
f = float(input(" Frequency: "))
print ("")
print (2 * math.pi * f * l)
time.sleep(delay)
cls()
# Capacitance
elif (value == 36):
print ("")
c = float(input(" Capacity: "))
print (' ----------------------------')
f = float(input(" Frequency: "))
print ("")
print (1 / (2 * math.pi * f * c))
time.sleep(delay)
cls()
# Power
elif (value == 46):
print ("")
u = float(input(" Voltage: "))
print (' ----------------------------')
i = float(input(" Current: "))
print ("")
print (u * i)
time.sleep(delay)
cls()
# Current
elif (value == 56):
print ("")
u = float(input(" Voltage: "))
print (' ----------------------------')
r = float(input(" Resistance: "))
print ("")
print (u / r)
time.sleep(delay)
cls()
# Voltage
elif (value == 66):
print ("")
r = float(input(" Resistance: "))
print (' ----------------------------')
i = float(input(" Current: "))
print ("")
print (r * i)
time.sleep(delay)
cls()
else:
print("I don't know what you write, try again")
else:
print("I don't know what you write, try again")