我在做一个游戏,想把所有的问题都讲一遍。如果用户的回答是错误的,我想知道这发生了多少次。在
我对这个代码有点问题。当我运行所有程序时,第一个和第二个函数运行正常。但当我想打印x\u错误时,它会说“name‘answer’is not defined”。我不明白,因为在我的代码里,答案是“10”、“20”和“30”。希望有人能帮助我更好地理解这一点。我感谢所有的帮助!在
代码:def question():
input_question("How old are Ring?", "10")
input_question("How old are King?", "20")
input_question("How old are Bing?", "30")
def input_question(question, answer):
print(question)
user_answer = input("Your answer: ")
wrong = 0
while user_answer != answer:
wrong = 1
print("Try again")
user_answer = input("Your answer: ")
print("Correct!")
return wrong
question()
x_errors = input_question(question, answer)
print(x_errors)
谢谢你!在