Here's the code. If it can't recognise timesRestarted
, how comes it recognises decisionList
? Does the error only happens when comparing?
def solution():
sequence = [1, 3, 2, 1]
decisionList = ["bigger", "smaller", "smaller"]
timesRestarted = 0
ultDec = ""
def findIrregular():
e = 0
for e in range(e, len(decisionList)-1):
num3 = e
num4 = e + 1
if timesRestarted == 1:
ultDec = "false"
else:
if decisionList[num3] != decisionList[num4]:
sequence.remove(e + 1)
timesRestarted = timesRestarted + 1
comparing()
else:
ultDec = "true"
print(ultDec)
findIrregular()
solution()
error:
Traceback (most recent call last):
File "<string>", line 22, in <module>
File "<string>", line 21, in solution
File "<string>", line 11, in findIrregular
UnboundLocalError: local variable 'timesRestarted' referenced before assignment
I have tried placing global timesRestarted
inside findIrregular()
but it just comes up with this error:
Traceback (most recent call last):
File "<string>", line 23, in <module>
File "<string>", line 22, in solution
File "<string>", line 12, in findIrregular
NameError: name 'timesRestarted' is not defined