-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformula.py
68 lines (64 loc) · 2.76 KB
/
formula.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
import sys
formulas = []
with open('formulas.txt', mode='r', encoding="utf-8") as file:
readfile = file.readlines()
for f in readfile:
formulas.append(f)
isExit = True
while isExit:
user_input = input('Please Enter Geometrical Keyword whose formula you want? ')
results = []
isFound = False
for i in range(len(formulas)):
user_input = str(user_input).lower()
line = (str(formulas[i]).lower()).split(',')
if 'exit' in user_input or 'quit' in user_input:
sys.exit(0)
if (line[0] in user_input) and (line[1] in user_input):
if len(line)<=1:
print('1')
results.append('Formula for '+ line[0].title()+ ' is: '+ line[1])
else:
results.append('Formula for '+ line[0].title()+' of '+line[1].title()+ ' is: '+ line[2])
isFound = True
elif user_input in line[0]:
if len(line)<=2:
results.append('Formula for '+line[0].title()+' is: '+line[1])
else:
results.append('Formula for '+line[0].title()+' of '+line[1].title()+ ' is: '+line[2])
# print(str(formulas[i]))
isFound = True
elif user_input in line[1]:
# print('Please Enter what you want of ', line[1])
if len(line)<=2:
results.append('Formula for '+ line[0].title()+ ' is: '+ line[1])
else:
results.append('Formula for '+ line[0].title()+' of '+line[1].title()+ ' is: '+ line[2])
# print(str(formulas[i]))
isFound = True
if not isFound:
print("Sorry, I dont know the formula of", user_input)
value = input('Press V to store its formula, or Press any other character to escape: ')
if value[0].lower()=='v':
value = input('Enter formula for '+ user_input+": ")
try:
f = open("formulas.txt", "a")
f.write('\n'+user_input + ', ' + value)
f.close()
formulas = []
formulas.clear()
with open('formulas.txt', mode='r', encoding="utf-8") as file:
readfile = file.readlines()
for f in readfile:
formulas.append(f)
print('Thanks for Saving!!!')
except:
print('Sorry, Cannot be saved')
elif len(results)>1:
print("####- I HAVE FOUND MORE THAN 1 RESULTS, PLEASE ENTER SPECIFIC ONE -#### ")
for j in range(len(results)):
print(results[j].strip())
elif len(results) == 1:
print(results[0])
print('__________________________________________________')
results.clear()