Question.py のファイルを読み込んで、簡単な3択質問を作る練習をしているのですが、
実行すると、question_promptsの質問が順に表示されるのがなぜか理解できません。
class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer
# 31 Building a Multiple choice quiz from Question import Question question_prompts = [ "What color are apples?\n(a) Red/Green\n(b) Purple\n(c) Orange\n\n", "What color are Bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n", "What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n" ] questions = [ Question(question_prompts[0], "a"), Question(question_prompts[1], "c"), Question(question_prompts[2], "b"), ] def run_test(questions): score = 0 for question in questions: answer = input(question.prompt) if answer == question.answer: score += 1 print("You got " + str(score) + "/" + str(len(questions)) + " Correct") run_test(questions)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/11 12:49