Untitled
unknown
plain_text
a month ago
4.3 kB
1
Indexable
Never
from question_model import Question from data import question_data from quiz_brain import QuizBrain question_bank = [] for question in question_data: question_text = question["question"] question_answer = question["correct_answer"] new_question = Question(question_text, question_answer) question_bank.append(new_question) quiz = QuizBrain(question_bank) while quiz.still_has_questions(): quiz.next_question() print("You've completed the quiz!") print(f"Your final score is: {quiz.score}/{quiz.question_number}.") # data-module question_data = [ {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "The 2005 video game "Call of Duty 2: Big Red One" is not available on PC.", "correct_answer": "True", "incorrect_answers": ["False"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "In Until Dawn, both characters Sam and Mike cannot be killed under any means until the final chapter of the game.", "correct_answer": "True", "incorrect_answers": ["False"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "There are 2 player roles in Trouble in Terrorist Town.", "correct_answer": "False", "incorrect_answers": ["True"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": ""Resident Evil 7" is the first first-person Resident Evil game.", "correct_answer": "False", "incorrect_answers": ["True"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "Tony Hawk's extreme sports videogames revolve around performing professional BMX tricks.", "correct_answer": "False", "incorrect_answers": ["True"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "The game "Battlefield 1" takes place during World War I.", "correct_answer": "True", "incorrect_answers": ["False"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "In Pokémon Sun and Moon, a male Salandit can evolve to a Salazzle.", "correct_answer": "False", "incorrect_answers": ["True"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "In "Undertale", the main character of the game is Sans.", "correct_answer": "False", "incorrect_answers": ["True"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "Activision created Battlefield 1.", "correct_answer": "False", "incorrect_answers": ["True"]}, {"type": "boolean", "difficulty": "easy", "category": "Entertainment: Video Games", "question": "In "Space Station 13", the station has a clown aboard it.", "correct_answer": "True", "incorrect_answers": ["False"]}] #QuizBrain module class QuizBrain: def __init__(self, question_list): self.question_number = 0 self.question_list = question_list self.score = 0 def still_has_questions(self): return self.question_number < len(self.question_list) def next_question(self): current_question = self.question_list[self.question_number] self.question_number += 1 user_answer = input(f"Q.{self.question_number}: {current_question.text} (True/False)?: ").lower() self.check_answer(user_answer, current_question.answer) def check_answer(self, user_answer, correct_answer): if user_answer.lower() == correct_answer.lower(): print("You got it right!") self.score += 1 else: print("You got it wrong.") print(f"The correct answer was: {correct_answer}") print(f"Your current score is: {self.score}/{self.question_number}.\n") #Question_Model class Question: def __init__(self, text, answer): self.text = text self.answer = answer
Leave a Comment