Skip to content

Commit af72393

Browse files
committed
Quiz Game
1 parent a5348a2 commit af72393

8 files changed

+81
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

Quiz Game/Quiz_Game/data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
question_data = [
3+
{"text": "A slug's blood is green.", "answer": "True"},
4+
{"text": "The loudest animal is the African Elephant.", "answer": "False"},
5+
{"text": "Approximately one quarter of human bones are in the feet.", "answer": "True"},
6+
{"text": "The total surface area of a human lungs is the size of a football pitch.", "answer": "True"},
7+
{"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"},
8+
{"text": "In London, UK, if you happen to die in the House of Parliament, you are entitled to a state funeral.", "answer": "False"},
9+
{"text": "It is illegal to pee in the Ocean in Portugal.", "answer": "True"},
10+
{"text": "You can lead a cow down stairs but not up stairs.", "answer": "False"},
11+
{"text": "Google was originally called 'Backrub'.", "answer": "True"},
12+
{"text": "Buzz Aldrin's mother's maiden name was 'Moon'.", "answer": "True"},
13+
{"text": "No piece of square dry paper can be folded in half more than 7 times.",
14+
"answer": "False"},
15+
{"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"}
16+
]

Quiz Game/Quiz_Game/main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from question_model import Question
2+
from data import question_data
3+
from quiz_brain import QuizBrain
4+
question_bank = []
5+
for question in question_data:
6+
question_text = question["text"]
7+
question_answer = question["answer"]
8+
new_question = Question(question_text,question_answer)
9+
question_bank.append(new_question)
10+
11+
quiz = QuizBrain(question_bank)
12+
13+
while quiz.still_has_questions():
14+
quiz.next_question()
15+
16+
print("You've completed the quiz")
17+
print(f"Your final score was : {quiz.score}/{quiz.question_number}")
18+
print("\n")

Quiz Game/Quiz_Game/question_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Question:
2+
def __init__(self, q_text, q_answer):
3+
self.text = q_text
4+
self.answer = q_answer
5+

Quiz Game/Quiz_Game/quiz_brain.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class QuizBrain:
2+
def __init__(self,q_list):
3+
self.question_number = 0
4+
self.score = 0
5+
self.question_list = q_list
6+
7+
def still_has_questions(self):
8+
return self.question_number < len(self.question_list)
9+
10+
def next_question(self):
11+
current_question = self.question_list[self.question_number]
12+
self.question_number += 1
13+
user_answer= input(f"Q.{self.question_number}: {current_question.text} (True/False): ")
14+
self.check_answer(user_answer, current_question.answer)
15+
16+
def check_answer(self, user_answer, current_answer):
17+
if user_answer.lower() == current_answer.lower():
18+
self.score += 1
19+
print("You got it right..!!")
20+
else:
21+
print("That's wrong..!")
22+
print(f"The correct answer was {current_answer}")
23+
print(f"Your current score is {self.score}/{self.question_number}")
24+
print("\n")

Quiz Game/first_class.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class User:
2+
def __init__(self, user_id, username): # constructor
3+
self.id = user_id
4+
self.username = username
5+
self.followers = 0
6+
self.following = 0
7+
def follow(self,user):
8+
user.followers += 1
9+
self.following += 1
10+
11+
user_1 = User("010", "shree")
12+
user_2 = User("002", "Ram")
13+
14+
user_1.follow(user_2)
15+
print(user_1.followers)
16+
print(user_1.following)
17+
print(user_2.followers)
18+
print(user_2.following)

0 commit comments

Comments
 (0)