I started programming in Python as a hobby a few weeks ago, and I have run into a little problem. I am currently making a script to give me a sort of Vocabulary Test. It is kind of hard to explain so I will just show you the code.
words = ["aero", "aesthet", "andr", "arch", "arch", "ast", "baro",\
"biblio", "bio", "cardi", "chron", "cosm", "crat", "cycl", "dem", "dont",\
"dogma", "dox", "esth"]
answers = ["air", "sense", "man", "man", "chief", "ancient", "star", "weight",\
"book", "life", "heart", "time", "universe", "rule", "circle", "people",\
"tooth", "opinion", "belief", "feeling"]
a = 0
def test():
a = a + 1
print "What does", words[a], "mean?"
ans = raw_input("> ")
if ans == answers[a]:
print "Correct!"
test()
else:
print "That is incorrect. Try again."
a = a - 1
test()
test()
So, the error I get is:
Traceback (most recent call last):
File "C:\Users\Pat\Python Scripts\Scripts in Progress\Testing - Copy (10).py", line 26, in <module>
test()
File "C:\Users\Pat\Python Scripts\Scripts in Progress\Testing - Copy (10).py", line 15, in test
a = a + 1
UnboundLocalError: local variable 'a' referenced before assignment
I made my script thinking I would just be able to loop through all of the words, except since I am having a problem with my "a" variable I am stuck... And I am pretty sure I have another bug in my script with returning "a"...
Would anybody be able to help?
Thanks in advance.