h College, Mu
ing zaff
S
ng at a
rp
La
ur
(Run under BRABU Bihar University)
A Mini Project Report on
Online Quiz Application
For Python (502 and 506)
Name: Khushi Kumari
Roll: 09
University Roll: 226008
Session: 2022 – 25
Reg. No.: 133201119400922/22
Guided By: Mr. Ravikant Sir
Submitted to: Department of B.C.A., Langat Singh
College, Muzaffarpur, Bihar
Content
S.no. Content Page No.
1. Acknowledgement 1
2. Declaration 2
3. Project Report 3-4
4. Hardware and Software 5
Requirements
5. MySQL Schema 6-7
9. Project Scope 8
10. Future Enhancement 9-10
11. Method 11
12. User Guide 12-13
13. Source Code 14-22
14. Output 23
15. Testing 24-26
16. Maintenance 27
17. Bibliography 28
Acknowledgement
I would like to express my sincere gratitude to my Principal
Prof. Dr. O.P. Roy Sir and my Teacher Mr. Ravikant Sir for
their invaluable guidance, support, and encouragement
throughout the course of this project. Their expertise and
feedback have been instrumental in the completion of this
project.
I am also grateful to the officials of Department of B.C.A.,
Langat Singh College for providing the resources and
facilities needed to complete this work. My heartfelt thanks
go to my friends and family for their constant support and
motivation.
Lastly, I wish to thank everyone who contributed directly or
indirectly to the successful completion of this project.
Thank you.
Declaration
I, Khushi Kumari, hereby declare that the mini project entitled
"Online Quiz Application" submitted in partial fulfilment of the
requirements for BCA at Langat Singh College, Muzaffarpur is
entirely my own work, conducted under the guidance of Mr.
Ravikant Sir.
I affirm that:
1. The contents of this project report are original and have not
been submitted, in part or in whole, for any other degree or
qualification.
2. Any sources of information used in this project report have
been properly acknowledged and referenced.
3. The experiments, analyses, and findings presented in this
report are genuine and have not been manipulated or falsified
in any manner.
4. Any assistance received from individuals or institutions
during the course of this project has been duly acknowledged.
I understand that any act of plagiarism or academic dishonesty in
this project would constitute a breach of academic integrity and
could lead to disciplinary action.
Khushi Kumari
Date:
Project Report:
Online Quiz Application in Python
Introduction:
The Online Quiz Application is a desktop-based software
that enables users to take quizzes on various topics. It stores
user information, questions, and quiz results using a MySQL
database. The application is built using Python with Tkinter
for the graphical user interface (GUI). This report outlines
the design, functionality, and implementation details of the
project.
▪ Objective:
• To create an interactive quiz application where users
can answer multiple-choice questions.
• To store user data and quiz results in a MySQL
database for future retrieval and analysis.
• To provide feedback on incorrect answers, helping
users improve their knowledge.
System Functionality:
▪ Connecting to the Database
• Establishes a connection with the MySQL database
using the mysql.connector library.
▪ Fetching Questions
• Retrieves all quiz questions from the questions table.
▪ Storing User data
• Saves user information and their quiz score to the
users table after the quiz is completed.
▪ Starting the Quiz
• Prompts the user for their name, displays questions,
and tracks the score.
▪ Displaying Questions
• Displays each question along with four options,
allowing the user to select one.
▪ Checking Answers
• Verifies the user's selected option against the correct
answer and updates the score.
▪ Displaying Results
• Shows the final score and a summary of incorrectly
answered questions in a separate window.
Hardware and Software
Requirements
Hardware Requirements:
• Processor: Intel Core i3 or above.
• RAM: 2 GB or higher.
• Hard Disk: 100 MB of Free space.
Software Requirements:
• Python 3.1.11 or above.
• MySQL Server.
• MySQL Connector Library (mysql.connector).
• Tkinter (comes pre-installed with Python).
MySQL Schema
Database Creation:
CREATE DATABASE online_quiz;
USE online_quiz;
-- Create the 'questions' table
CREATE TABLE questions (
id INT AUTO_INCREMENT PRIMARY KEY,
question TEXT NOT NULL,
option1 VARCHAR(255) NOT NULL,
option2 VARCHAR(255) NOT NULL,
option3 VARCHAR(255) NOT NULL,
option4 VARCHAR(255) NOT NULL,
correct_answer VARCHAR(50) NOT NULL
);
-- Create the 'users' table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
user_name VARCHAR(100) NOT NULL,
score INT NOT NULL
);
--Questions in Question Table:
SELECT * FROM questions;
Project Scope
Introduction:
The scope of the Online Quiz Application includes the
design, development, and implementation of a desktop-
based quiz application using Python (Tkinter) and MySQL.
This scope outlines the functionalities, user interactions, and
future possibilities of the system, ensuring a clear
understanding of the project's boundaries and objectives.
Limitations:
• Requires a MySQL database setup for storing quiz
questions and user data.
• The application currently supports only multiple-choice
questions, with no provision for other question types
(e.g., true/false).
• The desktop-based nature limits the application’s
accessibility compared to a web-based solution.
Future Enhancement
Quiz Timer Feature:
• Implement a countdown timer for each question, adding
a time constraint to increase the challenge of the quiz.
• Automatically submit the user's selected answer when
the time expires, or move to the next question if no
answer is selected.
Category-Based Quizzes:
• Allow users to choose a category or topic before starting
a quiz, such as Science, Mathematics, History, or
General Knowledge.
• Store different categories of questions in the database
and filter questions based on the selected category.
User Authentication System:
• Add login and registration functionality for users using
their email and password.
Detailed Performance Analysis:
• Develop a feature that generates a detailed report of each
user's quiz performance, including scores, time taken per
question, and areas for improvement.
• Display visual charts using libraries like matplotlib to
present user progress over time.
Web-Based Version:
• Expand the application into a web-based platform using
frameworks like Flask, Django, or React.
• Host the quiz on a web server, allowing users to access it
from anywhere with an internet connection.
Method
Database Connection:
• Create tables like questions and users with fields to store
question text, options, correct answers, user names, and
scores.
Application Design:
• Use Python's Tkinter library to create a simple and
intuitive GUI for quiz interaction.
Backend Development:
• Write Python functions for tasks like connecting to the
MySQL database, fetching quiz questions, storing user
data, and checking answers.
User Guide
Installation:
1. Ensure that Python 3.1.11 or above is installed on your
system.
2. Install the required libraries using pip:
pip install mysql-connector-python
3. Set up the MySQL database:
• Create a database named online_quiz.
• Execute the provided SQL schema to create the
necessary tables.
4. Download and run the application script.
Getting Started:
1. Set up the MySQL database by creating a database
named online_quiz with the following tables:
• questions: Stores quiz questions and answer options.
• users: Stores user names and their scores.
2. Download and run the quiz_application.py script using
Python.
Starting the Quiz:
1. Open the quiz_application.py script by running the
following command in the terminal.
2. A window will open titled Online Quiz Application.
3. Click on the "Start Quiz" button.
4. A dialog box will appear asking for your name. Enter
your name and click OK to proceed.
Answering Questions:
1. A question will be displayed along with four answer
options.
2. Select one of the answer options by clicking the radio
button next to it.
3. Click the "Submit Answer" button to submit your
selected answer.
Viewing Your Score:
1. Once all questions have been answered, a message box
will appear showing your final score.
2. The score is displayed in the format:
"Your score is: X/Y"
where X is the number of correct answers and Y is the
total number of questions.
3. Click OK to close the message box.
Source Code
import tkinter as tk
from tkinter import messagebox, simpledialog
import mysql.connector
# Connect to the MySQL database
def connect_db():
try:
conn = mysql.connector.connect(
host='localhost',
user='root',
password='khushi@18',
database='online_quiz'
)
return conn
except mysql.connector.Error as err:
messagebox.showerror("Database Error", f"Error:
{err}")
return None
# Fetch questions from the database
def fetch_questions():
conn = connect_db()
if conn:
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT * FROM questions")
questions = cursor.fetchall()
conn.close()
return questions
return []
# Store the user's data in the database
def store_user_data(user_name, user_score):
conn = connect_db()
if conn:
cursor = conn.cursor()
try:
cursor.execute("INSERT INTO users (user_name,
score) VALUES (%s, %s)", (user_name, user_score))
conn.commit()
messagebox.showinfo("Success", "Your score has
been saved successfully.")
except mysql.connector.Error as err:
messagebox.showerror("Database Error", f"Error:
{err}")
finally:
conn.close()
# Start the quiz
def start_quiz():
global current_question_index, score, user_name,
incorrect_answers
user_name = simpledialog.askstring("Input", "Please enter
your name:")
if not user_name:
messagebox.showwarning("Warning", "Name is
required to start the quiz.")
return
current_question_index = 0
score = 0
incorrect_answers = [] # Initialize the list to store
incorrect answers
start_button.pack_forget() # Hide the start button
# Show the quiz elements
question_label.pack(pady=20)
option1_button.pack(anchor='w', padx=20)
option2_button.pack(anchor='w', padx=20)
option3_button.pack(anchor='w', padx=20)
option4_button.pack(anchor='w', padx=20)
submit_button.pack(pady=20)
display_question()
# Display the current question and options
def display_question():
if current_question_index < len(questions):
question_data = questions[current_question_index]
question_label.config(text=question_data['question'])
option_var.set(None) # Reset the selected option
option1_button.config(text=question_data['option1'])
option2_button.config(text=question_data['option2'])
option3_button.config(text=question_data['option3'])
option4_button.config(text=question_data['option4'])
else:
# End of quiz, show score and save user data
messagebox.showinfo("Quiz Completed",
f"{user_name}, your score is: {score}/{len(questions)}")
store_user_data(user_name, score)
show_incorrect_answers()
root.quit()
# Show incorrect answers in a new window
def show_incorrect_answers():
if incorrect_answers:
result_window = tk.Toplevel(root)
result_window.title("Incorrect Answers")
result_window.geometry("500x400")
tk.Label(result_window, text="Review Your Incorrect
Answers", font=("Arial", 16)).pack(pady=10)
for item in incorrect_answers:
question, user_answer, correct_answer = item
question_text = f"Q: {question}"
user_answer_text = f"Your Answer: {user_answer}"
correct_answer_text = f"Correct Answer:
{correct_answer}"
tk.Label(result_window, text=question_text,
wraplength=400, justify="left").pack(anchor='w', padx=10,
pady=5)
tk.Label(result_window, text=user_answer_text,
fg="red", wraplength=400, justify="left").pack(anchor='w',
padx=20)
tk.Label(result_window, text=correct_answer_text,
fg="green", wraplength=400,
justify="left").pack(anchor='w', padx=20)
# Check the user's answer and update the score
def check_answer():
global current_question_index, score
selected_option = option_var.get()
if selected_option:
question_data = questions[current_question_index]
if selected_option == question_data['correct_answer']:
score += 1
else:
# Store incorrect answers: question, user's selected
answer, and the correct answer
incorrect_answers.append(
(question_data['question'],
question_data[selected_option],
question_data[question_data['correct_answer']])
)
current_question_index += 1
display_question()
else:
messagebox.showwarning("Warning", "Please select an
option.")
# Main GUI setup
root = tk.Tk()
root.title("Online Quiz Application")
root.geometry("500x450")
current_question_index = 0
score = 0
questions = fetch_questions()
user_name = "" # To store the user's name
incorrect_answers = [] # List to store incorrectly answered
questions
# Question Label
question_label = tk.Label(root, text="", font=("Arial", 16),
wraplength=400, justify="center")
# Radio buttons for options
option_var = tk.StringVar()
option1_button = tk.Radiobutton(root, text="",
variable=option_var, value='option1', font=("Arial", 14))
option2_button = tk.Radiobutton(root, text="",
variable=option_var, value='option2', font=("Arial", 14))
option3_button = tk.Radiobutton(root, text="",
variable=option_var, value='option3', font=("Arial", 14))
option4_button = tk.Radiobutton(root, text="",
variable=option_var, value='option4', font=("Arial", 14))
# Submit button
submit_button = tk.Button(root, text="Submit Answer",
command=check_answer, font=("Arial", 14))
# Start Quiz Button
start_button = tk.Button(root, text="Start Quiz",
command=start_quiz, font=("Arial", 16))
start_button.pack(pady=40)
# Start the main loop
root.mainloop()
Output
Testing
1. MySQL (Just after Creation):
2. User name Entry:
3. Questions:
4. Showing Results:
5. Showing Wrong Answers:
6. Questions Table:
7. Users Table:
Maintenance
Database Maintenance:
• Backup Regularly
• Clean Old Data
• Optimize Tables:
Code Maintenance:
• Use Version Control
• Update Libraries
• Handle Errors
Security:
• Hash Passwords
• Limit Database Access
• Input Validation
Bug Fixes and Updates:
• Fix Bugs Quickly
• Test New Features
Bibliography
1. For Context:
https://chatgpt.com/
2. For Tkinter:
https://docs.python.org/3/library/tkinter.html