@PythinPython/

EquationSimplifier

No description

Files
• main.py
main.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
```
```unsimpequation = input('Enter an equation to simplify. Only accepts one variable "x", no factorials "!", no percents "%", no "sin" or "cos", no functions or operations that I do not know of, no "log" or roots, and no parenthesis "()".\n')
unsimpequation = unsimpequation.replace(' ', '')
if unsimpequation[0] != '-':
unsimpequation = '+' + unsimpequation
if unsimpequation[unsimpequation.find('=') + 1] != '-':
unsimpequation = unsimpequation[0:unsimpequation.find('=') + 1] + '+' + unsimpequation[unsimpequation.find('=') + 1:len(unsimpequation)]
print('Compacted - ' + unsimpequation)
equationlength = len(unsimpequation)
inspectdigit = 0
xvaluesR = []
numvaluesR = []
xvaluesL= []
numvaluesL = []
invalidstrings = '`[email protected]#\$%&()_[]{}\|:;"\',<>?qwertyuiopasdfghjklzcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
equationpassport = True
possiblenumbers = '1234567890'
possibleoperations = '^*-+/'
for digitchar in unsimpequation:
if digitchar in invalidstrings:
print('Invalid - ' + digitchar)
equationpassport = False
if equationpassport == True:
prenumber = ''
eqside = 'right'
while inspectdigit < equationlength:
if unsimpequation[inspectdigit] in possiblenumbers:
prenumber = prenumber + unsimpequation[inspectdigit]
elif unsimpequation[inspectdigit] == '=':
eqside = 'left'
elif unsimpequation[inspectdigit] in possibleoperations:
if eqside == 'right':
try:
if prenumber[2] == 'x':
xvaluesR.append(prenumber)
else:
numvaluesR.append(prenumber)
except:
numvaluesR.append(prenumber)
else:
try:
if prenumber[2] == 'x':
xvaluesL.append(prenumber)
else:
numvaluesL.append(prenumber)
except:
numvaluesL.append(prenumber)
inspectdigit = inspectdigit + 1
print('Values separated:' + str(xvaluesR) + '\n' + str(numvaluesR) + '\n' + str(xvaluesL) + '\n' + str(numvaluesL))```
Fetching token