Quiz Game
Quiz Game
SCHOOL
NAME :
REGISTER NUMBER :
QUIZ GAME
TEAM MEMBERS:
ADHARSH RAM.B
DEVESHWAR.S
VENKATESH.K
Mrs.Prathipa Baskaran Date:
CERTIFICATE
This is to certify that the project work entitled QUIZ GAME was done
under my supervision.
original work done by the candidate during the academic year 2023-2024.
TEACHER IN-CHARGE
EXAMINAR EXAMINAR
SCHOOL SEAL
ACKNOWLEDGEMENT
2 INTRODUCTION 7
3 OBJECTIVE 8
4 MODULE DESCRIPTION 9
5 SYSTEM REQUIREMENTS 11
6 SOURCE CODE 19
7 OUTPUT 41
8 ADVANTAGES 43
9 CONCLUSIONS 45
10 REFERENCES 46
ABSTRACT
A quiz is a form of game or mind sport in which players
attempt to answer questions correctly on one or several specific
topics. Quizzes can be used as a brief assessment in education and
similar fields to measure growth in knowledge, abilities, and skills, or
simply as a hobby.
User Interaction: The game prompts users for input, such as the
number of players, player names, subject choices, time limits, and answers.
EASY TO ACCESS:
This program is very easy to access as it does not have
any special request to do so. As the program asks input which are
easy to understand.
USER SPECIFIC:
MODIFICATION:
1. *Class Structure:*
- QuizGame: Represents the main class for the quiz game.
- Attributes:
- player_profiles: Dictionary to store player information,
including scores, consecutive correct answers, and IQ levels.
- rounds: Total number of rounds in the game.
- current_round: Tracks the current round being played.
- leaderboard: Dictionary to keep track of players' total
scores.
- timer_interval: Interval for updating the timer in seconds.
- answered_within_time_limit: Flag to track whether a player
answered within the time limit.
- user_answer: Stores the user's answer during the quiz.
- num_questions_per_round: Number of questions to ask in
each round.
2. *Methods:*
- display_intro: Displays introductory messages to players.
- initialize_player_profiles: Takes input to initialize player
profiles.
- get_positive_integer_input: Takes user input and ensures it is
a positive integer.
- time_is_up: Prints a message when the time for answering a
question is up.
- timer_thread: Manages a timer for each question in a
separate thread.
- choose_subject: Allows players to choose a subject for the
current round.
- load_question_pool: Loads questions based on the chosen
subject.
- display_scores: Displays scores for each player.
- play_round: Conducts a round of the quiz game for each
player.
- update_leaderboard: Updates the overall leaderboard based
on players' scores.
- display_winner: Displays the winner(s) of the quiz game.
- play_game: Orchestrates the entire quiz game, including
rounds and final results.
- calculate_final_scores: Calculates final scores, considering
bonus points for consecutive correct answers.
- determine_iq_level: Determines IQ level based on the
number of correct answers.
- display_leaderboard: Displays the final leaderboard with
scores and IQ levels.
3. *Execution:*
- An instance of the QuizGame class is created, and the
play_game method is called to start the game.
SYSTEM REQUIREMENTS
1. *Python Interpreter:*
- Ensure that you have Python installed on your system. The
code appears to be compatible with Python 3.
2. *Threading Support:*
- The program uses threading to manage timers. Most standard
Python installations include threading support, so this should not
be an issue.
3. *Standard Input/Output:*
- The code relies on standard input (input()) and output
(print()) for user interaction. Ensure that your system supports
these standard I/O operations.
4. *Random Module:*
- The usage of the random module for question selection
assumes that the Python interpreter includes the random module,
which is a part of the standard library.
5. *Datetime Module:*
- The datetime module is used for handling time-related
operations. This module is a standard part of Python.
6. *System Resources:*
- The program should not have demanding system resource
requirements. It primarily relies on basic Python functionality
and does not involve complex computations.
7. *Console/Command-Line Execution:*
- The program is designed to be run in a console or command-
line environment. Ensure that you can run Python scripts from
your terminal or command prompt.
Start game
1. *Python Interpreter:*
NO
If subject ==
Mathematics
YES
NO
YES
If subject==
NNPhysics
NO
YES If subject ==
Chemistry
NO
YES
If subject ==
Computer science
NO
Enter how many
mquestions for the
Print invalid
njnkkround
subject
Display the
questionste Scores
NO
If the option is
correct
YES
Print correct Print wrong
option option
End game
SOURCE CODE
import random
import threading
import datetime
import time
class QuizGame:
def _init_(self):
self.player_profiles = {}
self.rounds = 1
self.current_round = 1
self.leaderboard = {}
def display_intro(self):
self.player_profiles = {}
self.player_profiles[player_name] = {"score": 0,
"consecutive_correct": 0, "iq_level": ""}
while True:
try:
value = int(input(prompt))
if value > 0:
return value
else:
def time_is_up(self):
time.sleep(1)
if not self.answered_within_time_limit:
self.time_is_up()
def choose_subject(self):
if subject in subjects:
return subject
else:
return self.choose_subject()
physics_questions = [
math_questions = [
chemistry_questions = [
cs_questions = [
subject = subject.lower()
if subject == "physics":
return physics_questions
return math_questions
return chemistry_questions
else:
return self.choose_subject()
def display_scores(self):
print("\nCurrent Scores:")
subject = self.choose_subject()
questions = self.load_question_pool(subject)
self.display_scores()
asked_questions = set()
self.num_questions_per_round =
self.get_positive_integer_input("Enter the number of questions for
this round:")
for _ in range(self.num_questions_per_round):
if not remaining_questions:
break
question_data = random.choice(remaining_questions)
asked_questions.add(question_data["question"])
correct_option_index = question_data["answer"] - 1
options =
random.sample(range(len(question_data["options"])),
len(question_data["options"]))
for i, option_index in enumerate(options, start=1):
option = question_data["options"][option_index]
print(f"{i}. {option}")
correct_answer = correct_option_index + 1
question_start_time = datetime.datetime.now()
self.answered_within_time_limit = False
timer_thread = threading.Thread(target=self.timer_thread,
args=(question_start_time, user_time_limit))
timer_thread.start()
try:
user_answer_index =
self.get_positive_integer_input("Your answer (enter the option
number): ")
self.answered_within_time_limit = True
user_answer_index -= 1
user_answer = options[user_answer_index]
correct_answer -= 1
user_answer = None
timer_thread.join()
if user_answer == correct_answer:
self.player_profiles[player_name]["score"] += 1
self.player_profiles[player_name]["consecutive_correct"] += 1
else:
print(f"Explanation:{question_data['explanation']}\n")
self.player_profiles[player_name]["consecutive_correct"] = 0
self.current_round += 1
def update_leaderboard(self):
self.leaderboard[player_name] = 0
self.leaderboard[player_name] += data['score']
def display_winner(self):
max_score = max(self.leaderboard.values())
print("\nFinal Results:")
if len(winners) == 1:
else:
def play_game(self):
self.display_intro()
self.initialize_player_profiles(num_players)
self.play_round(num_players)
self.update_leaderboard()
self.calculate_final_scores()
self.display_leaderboard()
def calculate_final_scores(self):
# Calculate final scores, considering any additional factors
self.leaderboard[player_name] = final_score
iq_level = self.determine_iq_level(final_score)
data['iq_level'] = iq_level
if correct_answers >= 8:
return "Genius"
else:
return "Average"
def display_leaderboard(self):
print("\nFinal Leaderboard:")
sorted_leaderboard = sorted(self.leaderboard.items(),
key=lambda x: x[1], reverse=True)
iq_level = self.player_profiles[player_name]["iq_level"]
quiz_game = QuizGame()
quiz_game.play_game()
OUTPUT
ADVANTAGES
This quiz game program has several advantages:
efficiently and makes the user to feel free to access. This program is
not like other quiz games as it asks how many questions should be
asked and also asks how much time does the user need to answer for
each questions.
The main goal from the program is that to make quiz games
as questions that are meant to show in the program that is you can
program.
FUTURE WORKS
This program gives the oppurtunity to learn and experience
the student’s IQ based on the questions that the user answers. The
allows the user to get good knowledge about subjects. The program
https://www.wikipedia.org/
https://www.google.com