class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer我創(chuàng)建了上面的question_class.py文件并將其導(dǎo)入下面的quiz.py文件。我正在嘗試運行一個 while 循環(huán)來詢問用戶是否有興趣再次播放測驗。但是,代碼不會運行。如何在循環(huán)中再次正確插入播放?另外,我如何詢問用戶是否準(zhǔn)備好玩游戲并正確檢查輸入錯誤?這是我的第一個個人項目,并在完成初學(xué)者教程后嘗試學(xué)習(xí)如何編寫自己的項目。我感謝所有反饋。 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
提交
取消