MCQ using Class in Python
class question:
def __init__(self, prompt, answer):
self.prompt=prompt
self.answer=answer
then in next sheet
from next import question
question_prompt = [
"What is the color of apples?\n (a) Red/Green\n (b) Yellow\n (c) White\n\n ",
"What is the color of Bananas?\n (a) Red/Green\n (b) Yellow\n (c) White\n\n ",
"What is the color of Berry?\n (a) Red/Green\n (b) Yellow\n (c) White\n\n "
]
questions = [
question(question_prompt[0], "a"),
question(question_prompt[1], "b"),
question(question_prompt[2], "a"),
]
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(Question_prompt) + " correct"))
run_test(questions)
Comments
Post a Comment