I am rather new to Python. I am trying to create a self grading quiz. so far I only have two questions. I tried to assign a global variable for the number that the person gets right and the number of questions the person gets wrong. The program works correctly if all the correct answers are typed in; however any incorrect answer comes back as incorrect not being defined.
def test():
print "We are going to take a small quiz"
print "Lets start with what your name."
name = raw_input("What is your name?")
correct = [0]
incorrect = [0]
def q1():
print "What organization did Hellboy work for?"
answer = raw_input("Type your answer.").lower()
if answer == "bprd" or answer == "b.p.r.d":
print "Your are correct."
correct[0] += 1
else:
print "That is wrong."
incorret[0] += 1
q1()
def q2():
print "What is the name of Captain America's sidekick?"
answer = raw_input("Your answer please.").lower()
if answer =="bucky barnes" or answer == "falcon":
print "Your are right"
correct[0] += 1
else:
print "Sorry that in incorrect"
incorrect[0] += 1
q2()
print "Good job %s, you got %r questions right and %r questions wrong" % (name, correct, incorrect)
raw_input()
test()