錯誤,我得到的是:爲什麼我得到一個unboundLocalError?
UnboundLocalError: local variable referenced before assignment?
代碼:
def menu_option(index, count):
import random
random_number1 = random.randrange(1,31)
random_number2 = random.randrange(1,31)
if index == 1:
problem = random_number1 + random_number2
elif index == 2:
problem = random_number1 - random_number2
elif index == 3:
problem = random_number1 * random_number2
elif index == 4:
problem = random_number1 // random_number2
elif index == 5:
problem = random_number1 % random_number2
user_solution = get_user_solution(problem)
return check_solution(user_solution, solution, count)
請縮進代碼,它使我們更容易回答。 – JkShaw
哪一行發生錯誤? –
錯誤信息有點大......它包括髮生錯誤的行。你能發佈整個錯誤信息嗎? – tdelaney