Completed the Trivia Quiz Project!
Fix Day 17 README Add trivia demo
This commit is contained in:
parent
f462cc5ae0
commit
5f7dcd5629
8 changed files with 157 additions and 3 deletions
25
Day 17/quiz-game-start/quiz_brain.py
Normal file
25
Day 17/quiz-game-start/quiz_brain.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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)?: "
|
||||
)
|
||||
self.check_answer(user_answer, current_question.answer)
|
||||
|
||||
def check_answer(self, user_answer, correct_answer):
|
||||
if user_answer.lower() == correct_answer.lower():
|
||||
self.score += 1
|
||||
print("You got it right!")
|
||||
else:
|
||||
print("That's wrong.")
|
||||
print(f"The correct answer was: {correct_answer}.")
|
||||
print(f"Your current score is: {self.score}/{self.question_number}.\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue