-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_Quiz_Game
More file actions
65 lines (55 loc) · 2.69 KB
/
OOP_Quiz_Game
File metadata and controls
65 lines (55 loc) · 2.69 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
### question_model.py ###
class Question():
def __init__(self, q_text, q_answer):
self.text = q_text
self.answer = q_answer
### data.py ###
question_data = [
{"text": "A slug's blood is green.", "answer": "True"},
{"text": "The loudest animal is the African Elephant.", "answer": "False"},
{"text": "Approximately one quarter of human bones are in the feet.", "answer": "True"},
{"text": "The total surface area of a human lungs is the size of a football pitch.", "answer": "True"},
{"text": "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.", "answer": "True"},
{"text": "In London, UK, if you happen to die in the House of Parliament, you are entitled to a state funeral.", "answer": "False"},
{"text": "It is illegal to pee in the Ocean in Portugal.", "answer": "True"},
{"text": "You can lead a cow down stairs but not up stairs.", "answer": "False"},
{"text": "Google was originally called 'Backrub'.", "answer": "True"},
{"text": "Buzz Aldrin's mother's maiden name was 'Moon'.", "answer": "True"},
{"text": "No piece of square dry paper can be folded in half more than 7 times.", "answer": "False"},
{"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"}
### quiz_brain.py ###
class QuizBrain():
def __init__(self, q_list):
self.user_score = 0
self.question_number = 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 or False? ")
self.check_answer(user_answer, current_question.answer)
def still_has_question(self):
while len(self.question_list) > self.question_number:
self.next_question()
print(f"Your Final Score Is: {self.user_score} out of 12")
def check_answer(self, user_answer, correct_answer):
if user_answer.lower() == correct_answer.lower():
print("correct")
self.user_score += 1
else:
print("incorrect")
print(f"The correct answer is {correct_answer}")
print(f"Your Score Is: {self.user_score}/{self.question_number}")
print("\n")
### main.py ###
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain
question_bank = []
for i in question_data:
question_text = i["text"]
question_answer = i["answer"]
new_question = Question(question_text, question_answer)
question_bank.append(new_question)
quiz = QuizBrain(question_bank)
quiz.still_has_question()