I am trying to program a History quiz of different difficulties using functions but have run into some trouble regarding "global names". I have tried to correct this but nothing seems to be working.
The snippet code is:
#Checking Answers
def checkEasyHistoryQuestions():
score = 0
if hisAnswer1E == 'B' or hisAnswer1E == 'b':
score = score + 1
print "Correct!"
else:
print "Incorrect!"
if hisAnswer2E == 'A' or hisAnswer2E == 'a':
score = score + 1
print "Correct!"
else:
print "Incorrect!"
if hisAnswer3E == 'B' or hisAnswer3E == 'b':
score = score + 1
print "Correct!"
else:
print "Incorrect!"
print score
print "\n"
#History - Easy - QUESTIONS + INPUT
def easyHistoryQuestions():
print "\n"
print "1. What date did World War II start?"
print "Is it:", "\n", "A: 20th October 1939", "\n", "B: 1st September 1939"
hisAnswer1E = raw_input("Enter your choice: ")
print "\n"
print "2. When did the Battle of Britain take place?"
print "Is it: ", "\n", "A: 10th July 1940 – 31st October 1940", "\n", "B: 3rd July 1940- 2nd August 1940"
hisAnswer2E = raw_input("Enter your choice: ")
print "\n"
print "3. Who succeeded Elizabeth I on the English throne?"
print "Is it: ", "\n", "A. Henry VIII", "\n", "B. James VI"
hisAnswer3E = raw_input("Enter your choice: ")
print "\n"
checkEasyHistoryQuestions()
The error I'm getting is:
if hisAnswer1E == 'B' or hisAnswer1E == 'b':
NameError: global name 'hisAnswer1E' is not defined
I have tried to declare hisAnswer1E as a global variable within the function aswell as outside it.
For example:
print "\n"
print "1. What date did World War II start?"
print "Is it:", "\n", "A: 20th October 1939", "\n", "B: 1st September 1939"
global hisAnswer1E
hisAnswer1E = raw_input("Enter your choice: ")
print "\n"
And also:
global hisAnswer1E
#Checking Answers
def checkEasyHistoryQuestions():
score = 0
if hisAnswer1E == 'B' or hisAnswer1E == 'b':
score = score + 1
print "Correct!"
else:
print "Incorrect!"
Nothing seems to be working and I just keep getting the same error. Any ideas why?