-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz_brain.py
33 lines (21 loc) · 987 Bytes
/
quiz_brain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class QuizBrain:
def __init__(self,q_list):
self.question_number = 0
self.score = 0
self.question_list = q_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 still_has_question(self):
return len(self.question_list) > self.question_number
def check_answer(self, user_answer, correct_answer ):
if user_answer.lower() == correct_answer.lower():
print("You got it right! ")
self.score += 1
print(f"Your score is {self.score}/{self.question_number}.")
else:
print("That's wrong")
print(f"Your score is {self.score}/{self.question_number}.")
print(f"The correct answer is {correct_answer}.")