python记录输入次数_如何计算用户输入错误的次数

我在做一个游戏,想把所有的问题都讲一遍。如果用户的回答是错误的,我想知道这发生了多少次。在

我对这个代码有点问题。当我运行所有程序时,第一个和第二个函数运行正常。但当我想打印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)

谢谢你!在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值