Your problem is most likely indentation. Do you have multiple functions in your code? If so, make sure that the select_level function is not nested inside another function. I couldn't reproduce your error running your code as you provided it. But when I nested your function inside another function like this:
def my_other_function():
print "This is my other function"
def select_level():
"""Defines how a player selects a diffuclity, selects questions
and answers depending on user input,outputs selections.
"""
print ("Ready Player One! Select a level.")
level_name = raw_input("Type in easy, medium or hard\n").lower()
if level_name=="easy":
level(easy_level, blanks, easy_answers)
elif level_name=="medium":
level(medium_level, blanks, medium_answers)
elif level_name=="hard":
level(hard_level, blanks, hard_answers)
else:
print ("Please select easy, medium or hard")
And then try to call the select_level function it breaks with the same error you are getting. See how the second function is indented further than the first function? That is causing the error.
Because the function is nested inside the other function it is out of scope. For more information on scope in python, give this page a read.
In addition, there are two other problems with the code sample you provided.
Remove the indent on the last line of your code. So it looks like this:
def select_level():
"""Defines how a player selects a diffuclity, selects questions
and answers depending on user input,outputs selections.
"""
print ("Ready Player One! Select a level.")
level_name = raw_input("Type in easy, medium or hard\n").lower()
if level_name=="easy":
level(easy_level, blanks, easy_answers)
elif level_name=="medium":
level(medium_level, blanks, medium_answers)
elif level_name=="hard":
level(hard_level, blanks, hard_answers)
else:
print ("Please select easy, medium or hard")
print select_level()
When you use a print statement on a function it's going to try and print the return value. Your function does not have a return value, so you don't need the print statement at all. Remove it so your code looks like this:
def select_level():
"""Defines how a player selects a diffuclity, selects questions
and answers depending on user input,outputs selections.
"""
print ("Ready Player One! Select a level.")
level_name = raw_input("Type in easy, medium or hard\n").lower()
if level_name=="easy":
level(easy_level, blanks, easy_answers)
elif level_name=="medium":
level(medium_level, blanks, medium_answers)
elif level_name=="hard":
level(hard_level, blanks, hard_answers)
else:
print ("Please select easy, medium or hard")
select_level()