-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaths.py
More file actions
317 lines (246 loc) · 7.45 KB
/
maths.py
File metadata and controls
317 lines (246 loc) · 7.45 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
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
import math
def tro():
intro = (input("\n welcome to my calc"
" \n please enter the number below "
"\n"
"\n 1. decimal to binary "
"\n 2. binary to decimal "
"\n 3. add number"
"\n 4. subtract number"
"\n 5. multiply number"
"\n 6. divide number"
"\n 7. root"
"\n 8. modules"
"\n 9. Factorial"
"\n 10. sin"
"\n 11. cos"
"\n 12. tan"
"\n 13. natural log"
"\n 14. binary to text"
"\n 15. text to binary"
"\n 16. hexadecimal to decimal"
"\n 17. hexadecimal to decimal to binary"
"\n 18. password creator"
"\n 19. exit"
"\n == "))
print("\n")
if intro == "1":
bin()
elif intro == "2":
din()
elif intro == "3":
add()
elif intro == "4":
subtract()
elif intro == "5":
times()
elif intro == "6":
divide()
elif intro == "7":
r()
elif intro == "8":
modules()
elif intro == "9":
factorial()
elif intro == "10":
sin()
elif intro == "11":
cos()
elif intro == "12":
tan()
elif intro == "13":
in_1()
elif intro == "14":
bin_text()
elif intro == "15":
text_bin()
elif intro == "16":
hex_din()
elif intro == "17":
hex_din_bin()
elif intro == "18":
pass_creator()
elif intro == "19":
exit()
else:
ValueError(1, 19)
print("wrong")
tro()
def bin():
try:
print("welcome to decimal to binary ")
num = input("please enter your number ")
binary = []
while num != 0:
if num % 2 == 0:
num = num / 2
binary.insert(0, 0)
else:
num = (num - 1) / 2
binary.insert(0, 1)
print(binary)
except ValueError:
print("only numbers")
bin()
def din():
try:
bib = list(input("Enter a Binary number: "))
decimal = 0
for x in range(len(bib)):
digit = bib.pop()
if digit == "1":
decimal = decimal + pow(2, x)
print("Decimal is ", decimal)
except ValueError:
print("only number")
def add():
try:
num1 = float(input("enter your number: "))
num2 = float(input("enter your number: "))
print(num1, "+", num2, "=", num1 + num2)
except ValueError:
print("numbers only")
def subtract():
try:
num1 = float(input("enter your number: "))
num2 = float(input("enter your number: "))
print(num1, "-", num2, "=", num1 - num2)
except ValueError:
print("numbers only")
def times():
try:
num1 = float(input("enter your number: "))
num2 = float(input("enter your number: "))
print(num1, "*", num2, "=", num1 * num2)
except ValueError:
print("numbers only")
def divide():
try:
num1 = float(input("enter your number: "))
num2 = float(input("enter your number: "))
print(num1, "/", num2, "=", num1 / num2)
except ValueError:
print("numbers only")
def power():
try:
num1 = float(input("enter the base number: "))
num2 = float(input("enter the power number: "))
print(num1, "^", num2, "=", num1 ** num2)
except ValueError:
print("numbers only")
def r():
try:
num1 = float(input("enter the 1st number: "))
num2 = float(input("enter the 2nd number: "))
print(num1, " root ", num2, "=", num2 ** (1 / num1))
except ValueError:
print("numbers only")
def modules():
try:
num1 = float(input("enter the 1st number: "))
num2 = float(input("enter 2nd number: "))
print(num1, " % ", num2, "=", num1 % num2)
except ValueError:
print("numbers only")
def factorial():
try:
num1 = float(input("enter your 1st number: "))
num2 = float(input("enter your 2nd number: "))
total_num = num1 + num2
num2 = 1
while num1 > 1:
num2 *= num1
num1 = num1 - 1
print("n!(", num1, ")=", num2)
except ValueError:
print("numbers only")
def sin():
try:
num1 = float(input("enter your number: "))
print("sin(", num1, ")=", math.sin(num1))
except ValueError:
print("numbers only")
def cos():
try:
num1 = float(input("enter your number: "))
print("cos(", num1, ")=", math.cos(num1))
except ValueError:
print("numbers only")
def tan():
try:
num1 = float(input("enter your number: "))
print("tan(", num1, ")=", math.tan(num1))
except ValueError:
print("numbers only")
def in_1():
try:
num1 = float(input("enter your number: "))
print("In( ", num1, " )= ", math.log(num1))
except ValueError:
print("numbers only")
def bin_text():
try:
bin = input("enter your binary number: ")
binary_int = int(bin, 2)
byte_number = binary_int.bit_length() + 7 // 8
binary_array = binary_int.to_bytes(byte_number, "big")
ascii_text = binary_array.decode()
print(ascii_text)
except ValueError:
print("numbers only")
def text_bin():
try:
test_str = input("please enter your text: ")
print("the original string is : " + str(test_str))
res = ' '.join(format(ord(i), 'b') for i in test_str)
print("the string after binary conversion: " + str(res))
except ValueError:
print("numbers only")
def hex_din():
try:
test_string = input("enter your hexadecimal: ")
print("the original string: " + str(test_string))
res = int(test_string, 16)
print("the decimal number of hexadecimal string: " + str(res))
except ValueError:
print("numbers only")
def hex_din_bin():
try:
test_string = input("enter your hexadecimal: ")
print("the original string: " + str(test_string))
res = int(test_string, 16)
print("the decimal number of hexadecimal string: " + str(res))
num = res
binary = []
while num != 0:
if num % 2 == 0:
num = num / 2
binary.insert(0, 0)
else:
num = (num - 1) / 2
binary.insert(0, 1)
print("the binary number is: ", binary)
except ValueError:
print("numbers only")
def pass_creator():
import random
try:
chart = "§±1!2@€3£#4$5%6^7&8*9(0)-_=+qwertyuiopasdfghjkl;'[]\`~zxcvbnm,<.>/?:|}{}"
number = int(input("please enter the number of your password: "))
length = int(input("please enter your password length: "))
for e in range(number):
password = ''
for i in range(length):
password += random.choice(chart)
print(password)
f = open("password.txt", "w+")
f.write(password)
f.close()
except ValueError:
print("numbers only")
tro()
new = input("\n would you like to use it again == ")
while new == "yes" or new == "yh" or new == "sure" or new == "yeah":
tro()
else:
exit()