I'm a Python newbie. I wrote this code, but heard that declaring global variables isn't a good practice. What would be in this case the right way to write this function?
index = 0
def level_selection():
global index
level = raw_input("Choose the desired level of difficulty: easy, medium or hard")
if level.lower() == "easy":
return level1
if level.lower() == "medium":
return level2
if level.lower() == "hard":
return level3
else:
print "Error"
index += 1
if index < 3:
return level_selection()
return
level1 = "You selected easy"
level2 = "You selected medium"
level3 = "You selected hard"