Building a Multiple Choice Quiz
Question.py
class Question:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
from Question import Question
question_prompts = [
"What color are apples?\n(a) Red/Green\n(b) Purple\n(c) Orange\n\nAnswer : ",
"What color are bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\nAnswer : ",
"What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\nAnswer : "
]
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)
//Output : What color are apples?
// (a) Red/Green
// (b) Purple
// (c) Orange
//
// Answer : a
//
// What color are bananas?
// (a) Teal
// (b) Magenta
// (c) Yellow
//
// Answer : c
//
// What color are strawberries?
// (a) Yellow
// (b) Red
// (c) Blue
//
// Answer : b
//
// You got 3/3 correct.