class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer我创建了上面的question_class.py文件并将其导入下面的quiz.py文件。我正在尝试运行一个 while 循环来询问用户是否有兴趣再次播放测验。但是,代码不会运行。如何在循环中再次正确插入播放?另外,我如何询问用户是否准备好玩游戏并正确检查输入错误?这是我的第一个个人项目,并在完成初学者教程后尝试学习如何编写自己的项目。我感谢所有反馈。 from question_class import Question username = input("What is your name? ") print(f"Welcome, {username}!") play_again = 'y' while play_again == 'y': question_prompts = [ ] questions = [ Question(question_prompts[0], "b"), Question(question_prompts[1], "a"), ] def run_test(questions): score = 0 for question in questions: answer = input(question.prompt) if answer == question.answer: score += 1 print("You answered " + str(score) + "/" + str(len(questions)) + " correct.") play_again = input("Want to play again(y/n): ") run_test(questions)
添加回答
举报
0/150
提交
取消