diff --git a/GAMES/Quiz-Game-OOP/data.py b/GAMES/Quiz-Game-OOP/data.py new file mode 100644 index 00000000..81077739 --- /dev/null +++ b/GAMES/Quiz-Game-OOP/data.py @@ -0,0 +1,102 @@ +question_data = [ + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "medium", + "question": "The HTML5 standard was published in 2014.", + "correct_answer": "True", + "incorrect_answers": [ + "False" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "medium", + "question": "The first computer bug was formed by faulty wires.", + "correct_answer": "False", + "incorrect_answers": [ + "True" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "medium", + "question": "FLAC stands for 'Free Lossless Audio Condenser'.", + "correct_answer": "False", + "incorrect_answers": [ + "True" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "medium", + "question": "All program codes have to be compiled into an executable file in order to be run. This file can then be executed on any machine.", + "correct_answer": "False", + "incorrect_answers": [ + "True" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "Linus Torvalds created Linux and Git.", + "correct_answer": "True", + "incorrect_answers": [ + "False" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "The programming language 'Python' is based off a modified version of 'JavaScript'", + "correct_answer": "False", + "incorrect_answers": [ + "True" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "medium", + "question": "AMD created the first consumer 64-bit processor.", + "correct_answer": "True", + "incorrect_answers": [ + "False" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "'HTML' stands for Hypertext Markup Language.", + "correct_answer": "True", + "incorrect_answers": [ + "False" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "easy", + "question": "In most programming languages, the operator ++ is equivalent to the statement '+= 1'.", + "correct_answer": "True", + "incorrect_answers": [ + "False" + ] + }, + { + "category": "Science: Computers", + "type": "boolean", + "difficulty": "hard", + "question": "The IBM PC used an Intel 8008 microprocessor clocked at 4.77 MHz and 8 kilobytes of memory.", + "correct_answer": "False", + "incorrect_answers": [ + "True" + ] + } +] diff --git a/GAMES/Quiz-Game-OOP/main.py b/GAMES/Quiz-Game-OOP/main.py new file mode 100644 index 00000000..6c39d1dc --- /dev/null +++ b/GAMES/Quiz-Game-OOP/main.py @@ -0,0 +1,16 @@ +from data import question_data +from question_model import Question +from quiz_brain import QuizBrain + +quiz_list = [] +for question in question_data: + q_object = Question(question["question"], question["correct_answer"]) + quiz_list.append(q_object) + +quiz = QuizBrain(quiz_list) + +while quiz.still_has_question(): + quiz.next_question() + +print("You've completed the quiz") +print(f"Your final score was: {quiz.score}/{quiz.question_num}") \ No newline at end of file diff --git a/GAMES/Quiz-Game-OOP/question_model.py b/GAMES/Quiz-Game-OOP/question_model.py new file mode 100644 index 00000000..5b09db6c --- /dev/null +++ b/GAMES/Quiz-Game-OOP/question_model.py @@ -0,0 +1,4 @@ +class Question: + def __init__(self, text, answer): + self.text = text + self.answer = answer \ No newline at end of file diff --git a/GAMES/Quiz-Game-OOP/quiz_brain.py b/GAMES/Quiz-Game-OOP/quiz_brain.py new file mode 100644 index 00000000..8c2ce67f --- /dev/null +++ b/GAMES/Quiz-Game-OOP/quiz_brain.py @@ -0,0 +1,24 @@ +class QuizBrain: + def __init__(self, question_list): + self.question_list = question_list + self.score = 0 + self.question_num = 0 + + def still_has_question(self): + return self.question_num < len(self.question_list) + + def next_question(self): + current_question = self.question_list[self.question_num] + self.question_num += 1 + user_answer = input(f"Q.{self.question_num}: {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_num}") + print("\n")