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

Popular posts from this blog

Multiple linear regression for GW depth estimaition

Class in Python

To check if a student has a honor's degree (Using Class in python)