-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMy_math_app.py
159 lines (147 loc) · 6.44 KB
/
My_math_app.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
class calculator :
def __init__(self, num1, num2) :
self.num1=num1
self.num2=num2
def sum(self):
return self.num1+self.num2
def Submission(self):
return self.num1-self.num2
def Multiplication(self):
return self.num1*self.num2
def Division(self):
return self.num1/self.num2
def fib(a):
fib = [0, 1, 1]
for i in range(3, No+1) :
fib.append(fib[i-2]+fib[i-1])
return fib
def morabe(a, b):
mohit = 2 *(tool + arz)
masahat = tool*arz
return masahat , mohit
# def bmmfunc(*args):
# bmm = gcd(args[0],args[1])
# print(bmm)
while True :
from math import *
selector = input('Choose : Calculator of 2 numbers(cal) , Algebra sets(set) , Recognize being a prime number(pr) , Prime numbers list(prlist) , Factorial calculation(fact) , Calculate the perimeter and area(ea) , Fibonacci numbers(fib) , The largest common denominator of two numbers(cd) , About app(about) , To close app(close) : ')
selector = selector.lower()
if selector == 'ea':
try:
tool = float(input('The length: '))
arz = float(input('Width: '))
print( 'area: %f and perimeter: %f ' % morabe(arz, tool))
except:
print('something is wrong! :( try again....')
elif selector == 'fib':
try:
No = int(input('Until the : '))
print(fib(No))
except:
print('something is wrong! :( try again....')
elif selector == 'pr':
try:
Nom = int(input('Enter No : '))
Up = ceil(sqrt(Nom))
if Nom == 2:
print("%i is prime!" % Nom)
else:
for m in range(2, Up+1):
if Nom%m == 0:
print('%i is not prime!' % Nom)
break
else:
if Nom == 1:
print('%i is not prime!' % Nom)
else:
print("%i is prime!" % Nom)
except:
print('something is wrong! :( try again....')
elif selector == 'prlist':
try:
No1 = int(input('From : '))
No2 = int(input('Until : '))
l = []
if No1 < 2:
l.append(2)
No11 = No1
for No1 in range(No1,No2):
Up = ceil(sqrt(No1))
for m in range(2, Up+1):
if No1 % m == 0:
break
else:
if No1 == 1:
pass
else:
l.append(No1)
No1 += 1
ml = str(l)
print('Prime numbers from %i to %i : %s' % (No11,No2,ml))
except:
print('something is wrong! :( try again....')
elif selector == 'cd' :
try:
no1 = int(input('No1: '))
no2 = int(input('No2: '))
bmm = gcd( no1 , no2 )
print('The largest common denominator of two numbers :', bmm )
no3 = int(input('No3: '))
bmm2 = gcd( bmm , no3 )
print('The largest common denominator of two numbers :', bmm2 )
no4 = int(input('No4: '))
bmm3 = gcd(bmm2, no4)
print('The largest common denominator of two numbers : ', bmm3)
no5 = int(input('No5: '))
bmm4 = gcd(bmm3, no5)
print('The largest common denominator of two numbers : ', bmm4)
except:
print('something is wrong! :( try again....')
elif selector == 'set' :
try:
a = [int(input( 'No1 a : ')) , int(input( 'No2 a : ')), int(input( 'No3 a : ')), int(input( 'No4 a : '))]
b = [int(input( 'No1 b : ')) , int(input( 'No2 b : ')), int(input( 'No3 b : ')), int(input( 'No4 b : '))]
zarbdd = [a[0]*b[0], a[0]*b[1], a[0]*b[2], a[0]*b[3], a[1]*b[0], a[1]*b[1], a[1]*b[2], a[1]*b[3], a[2]*b[0],a[2]*b[1], a[2]*b[2], a[2]*b[3] , a[3]*b[0], a[3]*b[1], a[3]*b[2], a[3]*b[3]]
gamdd = [a[0]+b[0], a[0]+b[1], a[0]+b[2], a[0]+b[3], a[1]+b[0], a[1]+b[1], a[1]+b[2], a[1]+b[3], a[2]+b[0],a[2]+b[1], a[2]+b[2], a[2]+b[3], a[3]+b[0], a[3]+b[1], a[3]+b[2] , a[3]+b[3]]
agtema = set(a)|set(b)
tafazol = set(a)-set(b)
tafazol2 = set(b)-set(a)
eshterak = set(b)&set(a)
zirma = 2**len(a)
zirmb = 2**len(b)
print('\n Number of subsets of a :' , zirma ,'\n Number of subsets of b :' , zirmb ,'\n Multiply sets by sets (persian : zarb doone be doone) : ', zarbdd , '\n Collect one by two collections (persian : game doone be doone) : ', gamdd ,'\n a-b :',tafazol,'\n b-a :',tafazol2,'\n union of 2 sets : ', agtema, '\n intersection of 2 sets : ', eshterak)
except:
print('something is wrong! :( try again....')
elif selector == 'fact' :
try:
N = int(input('No : '))
print('%i! = %i' % (N, factorial(N)))
except:
print('something is wrong! :( try again....')
elif selector == 'cal' :
try:
a = int(input('No1 : '))
b = int(input('No2 : '))
mycalc = calculator(a,b)
selector = input('choose : Addition(a), Subtraction(sub), Multiplication(m), Division(d), All operations!(all) : ')
selector = selector.lower()
if selector == 'a' :
print(a, '+', b, '=', mycalc.sum())
elif selector == 'sub' :
print(a, '-', b, '=', mycalc.Submission())
elif selector == 'm' :
print(a, '×', b, '=', mycalc.Multiplication())
elif selector == 'd' :
print(a, '÷', b, '=', mycalc.Division())
elif selector == 'all' :
print('', a, '+', b, '=', mycalc.sum() , '\n', a, '-', b, '=', mycalc.Submission(),'\n', a, '×', b, '=', mycalc.Multiplication(), '\n', a, '÷', b, '=', mycalc.Division())
else:
print('Error!!!, please try again')
except:
print('something is wrong! :( try again....')
elif selector == 'close':
break
elif selector == 'about':
print('\nAbout Application : \n Written in the Python programming language! \n In 150 lines of code! \n And by Elman Shokri \n \nContact with me! : \n E-mail : elmanshokritz1384@gmail.com \n Telegram id : @ElmanTr \n \n Thank you for using the app!')
else:
print('Error!!!, please try again')