Sample Python Code:
python
Copy code
class Question:
def __init__(self, prompt, options, answer):
self.prompt = prompt
self.options = options
self.answer = answer
def is_correct(self, user_answer):
return user_answer.lower() == self.answer.lower()
class TestBank:
def __init__(self):
self.questions = []
def add_question(self, prompt, options, answer):
question = Question(prompt, options, answer)
self.questions.append(question)
def view_questions(self):
if not self.questions:
print("No questions in the test bank yet.")
return
for i, question in enumerate(self.questions):
print(f"Q{i+1}: {question.prompt}")
for j, option in enumerate(question.options):
, print(f" {chr(97 + j)}. {option}")
print(f" (Answer: {question.answer})\n")
def take_test(self):
if not self.questions:
print("No questions available for the test.")
return
score = 0
for question in self.questions:
print(f"{question.prompt}")
for j, option in enumerate(question.options):
print(f" {chr(97 + j)}. {option}")
answer = input("Your answer: ").strip()
if question.is_correct(answer):
score += 1
print("Correct!\n")
else:
print(f"Incorrect! The correct answer is {question.answer}\n")
print(f"Test finished! Your score is {score}/{len(self.questions)}\n")
# Example usage of TestBank
def main():
test_bank = TestBank()
# Adding some questions
test_bank.add_question(
"What is the capital of France?",