I've just started python and I've decided to start with a simple program to parse a single line, two argument mathematical expression directly into an answer. Examples: 4 + 2, 3/4, 5435 * 3423, ect. To start with I'm trying to interpret the two variables in the equation before I work on having the program mathify them. My problem is the lines 39, 40, 42, and 43 are not modifying their respective variables at 1, 3, 2, and 5. In PyCharm, they are greyed out with an error about shadowing names out of scope.
It is currently almost 1AM and I'm not much of a night owl (I'll never make it as a coder lol) so it's probably a stupid mistake on my part but just in case...
primeNumber = None
secNumber = None
num11 = 0
buildList = []
finished = False
def interpret(statement):
i = 0
iMax = len(statement)
while True:
if i >= iMax:
break
parse(statement[i])
i = i + 1
def parse(char, buildList=buildList):
interrupt = [" ", "+", "-", "/", "*"]
if char in interrupt:
buildNumber(buildList)
buildList.clear()
elif num11 == 1:
buildNumber(buildList)
buildList.clear()
else:
buildList.append(char)
def isNumber(att):
try:
int(att)
return True
except ValueError:
return False
def buildNumber(finishedList, num11 = num11):
finishedNumber = ''.join(finishedList)
print(finishedNumber)
if num11 == 0:
primeNumber = finishedNumber # <<< line 39
num11 = 1
elif num11 == 1:
secNumber = finishedNumber
finished = True
Aucun commentaire:
Enregistrer un commentaire