Computer Science
PROJECT FILE
Saket Choubey
Class – XII – A
Roll. No. - 23
CERTIFICATE
This is to certify that Saket Choubey has
successfully completed his Computer Project File
on Quiz Management under my guidance and
supervision during the academic year 2024-25.
I am satisfied with his initiative and efforts in
completing the project file as part of the CBSE
Class XII Curriculum.
Date: ______________
Supervisor's Name :
Designation :
Supervisor’s Signature :
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to
my Computer Science teacher, Mr. Vivek
Dagur, for his invaluable guidance, constant
support, and encouragement throughout the
completion of this project. Their expertise and
constructive feedback were instrumental in
shaping this work.
I would also like to extend my heartfelt thanks to
the Principal, Ms. Archana Narain, for providing
me with the opportunity to work on this project
and for her continuous encouragement, which
motivated me to put in my best efforts.
My sincere thanks go to my classmates, whose
collaboration and assistance were crucial during
the process. Their ideas, suggestions, and
teamwork have contributed significantly to the
success of this project.
Lastly, I am deeply grateful to my parents for
their unwavering support and understanding.
Their constant encouragement, patience, and
belief in me have been a source of strength
throughout this journey.
Thank you all for your contributions and support.
INDEX
[Link]. TITLE PAGE NO.
01. AIM 1
02. INTRODUCTION – QUIZ MANAGEMENT 2
03. THEORETICAL BACKGROUND 3-4
04. APPARATUS 5-6
05. SOURCE CODE 7-18
06. OUTPUT 19-20
07. CONCLUSION 21
08. BIBILIOGRAPHY 22
AIM
The aim of the Quiz Management
System is to create a dynamic and
interactive mini game where quizzes
can be created, managed, and taken by
users. The system allows administrators
to manage quiz content, including
adding and updating questions and
options.
Users can participate in the quizzes,
decide the length of their quiz, answer
questions, skip them if needed, and
receive scores based on their
performance. The system is designed to
be user-friendly and flexible, offering
features such as random question
selection and real-time scoring, while
providing administrators with complete
control over the quiz database.
QUIZ MANAGEMENT
The Quiz Management System is a
comprehensive, Python-based application that
integrates with a MySQL database, designed to
streamline the process of managing and
conducting quizzes. It features two primary user
interfaces: one for administrators and one for
participants.
Administrators can easily add, update, and delete
quiz questions and their corresponding options,
ensuring that the quiz content remains up-to-
date and relevant. They also have the ability to
modify correct answers and adjust other details,
allowing for complete flexibility in quiz
management.
For participants, the system provides an
interactive and engaging experience. Users can
take quizzes with questions selected randomly
from the database, answer them, and receive
immediate feedback on their performance. The
application includes features such as skipping
questions, with the restriction that skipped
questions cannot be revisited, adding an element
of challenge. Scoring is dynamic: participants
earn points for correct answers, lose points for
incorrect answers, and receive no points for
skipped questions.
THEORETICAL
BACKGROUND
What is Python?
Python is a high-level, interpreted programming
language developed by Guido van Rossum in 1991.
Known for its simplicity and readability, Python is
open-source and supports object-oriented
programming, making it suitable for both beginners
and experienced developers.
Features of Python:
Interactive and Interpreted: Python is an interpreted
language that allows for quick testing and
debugging.
Object-Oriented: Supports OOP, enabling code reuse
and modular design.
Readable Syntax: Python’s simple syntax enhances
code clarity and maintainability.
Cross-Platform: Runs on various operating systems
like Windows, macOS, and Linux.
Extensible: Can be extended with other languages
such as C and C++.
GUI Support: Supports building graphical user
interfaces through frameworks like Tkinter.
Rich Libraries: Offers a wide range of libraries for
web development, data analysis, machine learning,
and more.
What is SQL?
SQL (Structured Query Language) is a standardized
language used for managing and manipulating
relational databases. It enables users to query,
insert, update, and delete data within a database.
Features of SQL:
Data Definition: Use commands like CREATE and
ALTER to define database structures.
Data Manipulation: Allows for querying (SELECT),
inserting (INSERT), updating (UPDATE), and deleting
(DELETE) data.
Relational Operations: Supports joins, grouping, and
sorting of data across multiple tables.
Data Integrity: Uses constraints like PRIMARY KEY
and FOREIGN KEY to maintain data accuracy.
Transaction Control: Supports commands like
COMMIT and ROLLBACK to ensure data consistency.
Cross-DBMS Compatibility: SQL is widely used
across various database systems, including MySQL,
PostgreSQL, and SQLite.
Together, Python and SQL make for an ideal duo for
this project as Python will be handling logic and SQL
managing data storage and retrieval.
APPARATUS REQUIRED
To complete this project we will need;
Hardware:
[Link] System:
o A computer with sufficient processing
power, memory, and storage for running
the Python application and managing a
MySQL database.
[Link] Connection:
o A stable internet connection for
downloading necessary software
packages and libraries, as well as
accessing online resources if needed.
[Link]:
o Keyboard and Mouse for interaction with
the system.
Software:
[Link] System:
o Windows, macOS, or Linux (compatible
with Python and MySQL)
[Link]:
o Python 3.x (latest version recommended)
to run the quiz management system.
[Link] Database Management System:
o MySQL (or compatible DBMS such as
MariaDB) installed for managing the quiz
database.
[Link]:
o A database named quiz_db with tables
for questions, options, and answers.
[Link] Editor or Integrated Development
Environment (IDE):
o A code editor like Visual Studio Code,
PyCharm, or IDLE to write and manage
the Python code.
[Link]/Modules:
o [Link]: To connect Python to
MySQL and interact with the database.
o random: For selecting random questions
from the database to be displayed to the
user.
o os: (Optional) For managing environment
variables or interacting with the system if
required.
SOURCE CODE
#1. Creating a Database in Python named
‘quiz_db’ with the following tables;
questions: Stores the question text and question ID.
options: Stores the options corresponding to each
question.
answers: Stores the correct answers.
user_responses : to store the user's responses and
scores.
mysql> CREATE
DATABASE quiz_db;
Query OK, 1 row
affected (0.01 sec)
mysql> USE quiz_db;
Database changed
mysql> CREATE TABLE
questions (
-> id INT
AUTO_INCREMENT
PRIMARY KEY,
-> question_text
VARCHAR(255) NOT
NULL
-> );
Query OK, 0 rows
affected (0.02 sec)
mysql> CREATE TABLE
options (
-> id INT
AUTO_INCREMENT
PRIMARY KEY,
-> question_id
INT,
-> option_text
VARCHAR(255) NOT
NULL,
-> FOREIGN KEY
(question_id)
REFERENCES
questions(id)
-> );
Query OK, 0 rows
affected (0.02 sec)
mysql> CREATE TABLE
answers (
#2. Creating a file in Python named
‘[Link]’ in which we will use to oversee all
the administrative work such as adding
questions and options to the database.
import [Link]
def connect_db():
connection = [Link](
host="localhost",
user="root",
passwd="Saket123",
database="quiz_db"
)
return connection
def add_question(question, options, correct_answer):
connection = connect_db()
cursor = [Link]()
[Link]("INSERT INTO questions (question_text)
VALUES (%s)", (question,))
[Link]()
question_id = [Link]
for option in options:
[Link]("INSERT INTO options (question_id,
option_text) VALUES (%s, %s)", (question_id, option))
[Link]("INSERT INTO answers (question_id,
correct_answer) VALUES (%s, %s)", (question_id,
correct_answer))
[Link]()
[Link]()
[Link]()
def prompt_user():
while True:
question = input("Enter the question (or type 'exit'
to quit): ")
if [Link]() == 'exit':
break
options = []
print("Enter options (you can only add up to 4
options):")
while len(options) < 4:
option = input(f"Option {len(options) + 1}: ")
[Link](option)
correct_answer = input("Enter the correct answer: ")
add_question(question, options, correct_answer)
print("Question added successfully!")
def main():
print("Welcome to the Quiz Admin Panel!")
prompt_user()
if __name__ == "__main__":
main()
On Running ‘[Link]’; an infinite loop started in which we
could start inputting data into the database; here’s some
screenshots to
show the process of making the database.
#3. Creating a file in Python named ‘[Link]’
which we will use to oversee all the quiz work
such as fetching random questions, inputting
answers and calculating total score.
import [Link]
from [Link] import Error
def connect_db():
try:
connection = [Link](
host="localhost",
user="root",
passwd="Saket123", # Ideally, use environment
variables or a config file to store credentials securely
database="quiz_db"
)
if connection.is_connected():
return connection
except Error as e:
print(f"Error while connecting to MySQL: {e}")
return None
def fetch_random_questions(limit):
connection = connect_db()
if connection is None:
print("Failed to connect to the database.")
return []
cursor = [Link](dictionary=True)
try:
[Link]("SELECT id, question_text FROM
questions ORDER BY RAND() LIMIT %s", (limit,))
questions = [Link]()
if not questions:
print("No questions found in the database.")
return []
for question in questions:
[Link]("SELECT option_text FROM options
WHERE question_id = %s", (question['id'],))
options = [Link]()
question['options'] = [option['option_text'] for
option in options]
[Link]("SELECT correct_answer FROM answers
WHERE question_id = %s", (question['id'],))
correct_answer = [Link]()
question['correct_answer'] =
correct_answer['correct_answer'] if correct_answer else None
except Error as e:
print(f"Error while fetching questions: {e}")
finally:
[Link]()
[Link]()
return questions
def start_quiz():
try:
num_questions = int(input("How many questions do you
want to attempt? "))
questions = fetch_random_questions(num_questions)
if not questions:
print("There are no questions available in the
database. Please add questions first.")
return
score = 0
for idx, question in enumerate(questions, start=1):
print(f"\nQuestion {idx}:
{question['question_text']}")
for opt_idx, option in
enumerate(question['options'], start=1):
print(f" {opt_idx}. {option}")
user_answer = input("Your answer (or type 'skip'
to skip): ").strip()
if user_answer.lower() == "skip":
print("Question skipped!")
continue
correct_answer = question['correct_answer']
if user_answer.lower() == correct_answer.lower():
print("Correct!")
score += 1
else:
print("Wrong!")
score -= 1
print(f"\nQuiz Over! Your final score is: {score}")
except ValueError:
print("Invalid input. Please enter a valid number of
questions.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
start_quiz()
#SOURCE CODE SCREENSHOTS
OUTPUT
CONCLUSION
With the help of Python and SQL, we
have successfully developed a Quiz
Management System that allows for
efficient administration and seamless
user interaction. By combining Python's
simplicity and flexibility, along with
SQL's robust database management
capabilities, we have created a dynamic
platform for storing and retrieving quiz
questions, options, and answers. This
system not only facilitates easy data
manipulation but also provides an
engaging quiz experience for users. The
integration of both technologies ensures
the system is efficient, scalable, and
user-friendly, making it a valuable tool
for managing quizzes in various
domains.
BIBILIOGRAPHY
Youtube
[Link]
[Link]
Reference Projects
Computer Science with Python
(By Sumita Arora)
[Link]