Cs Jai Shree
Cs Jai Shree
OLYMPIAD MODULE
DONE BY :
JAI sHREE.P
INDEX
1. ABOUT PYTHON
2. ABOUT TKINTER
3. ABOUT FILE HANDLING
4. PROJECT DESCRIPTION
5. SOFTWARE SPECIFICATION
6. SOURCE CODE
7. SAMPLE OUTPUT
8. CONCLUSION
9. INSTALLATION PROCEDURE
10. BIBLIOGRAPHY
1
ABOUT PYTHON:
Python programming language was developed by Guido Van Rossum in February 1991.
Python is based on or influenced with two programming languages:
➢ Modula-3
Often, programmers fall in love with Python because of the increased productivity it provides.
Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging
Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead,
when the interpreter discovers an error, it raises an exception. When the program doesn't catch
the exception, the interpreter prints a stack trace. A source level debugger allows inspection of
local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping
through the code a line at a time, and so on. The debugger is written in Python itself, testifying
to Python's introspective power.
2
ABOUT TKINTER:
Tkinter is a python program binding to the Tk GUI toolkit. It is the standard Python interface
to the Tk GUI toolkit, and is Python’s de facto standard GUI.Tkinter is included with standard
Linux, Microsoft Windows and Mac OS X installs of Python.Tk is a, cross-platform widget
toolkit that provides a library of basic elements of GUI widgets for building a graphical user
interface (GUI) in many programming languages.
The name Tkinter comes from Tk interface. Tkinter was written by Steen Lumholt and Guido
Van Rossum, then later revised by Fredrik Lundh. Like Tcl, Tk support Unicode within the
Basic Multilingual Plane, but it has not yet been extended to handle the current extended full
Unicode (e.g., UTF-16 from UCS-2 that Tk supports).
Customizable: Almost all the features of a widget in Tk are customizable through options
during the creation of the widget or later on through the configure command.
Configurable: Many of the options can be stored in an option database, making it very easy to
parameterize the look of an application (such as the color scheme). This also means that storing
the application-specific options is only a matter of saving the option add commands and
executing them on loading the application.
3
FEATURES OF TK:
Tk provides various widgets. Basic widgets are embedded into toplevel widgets, which in turn
are usually hosted by the operating system in floating windows that can be moved around on
the screen.
Basic widgets
Language bindings:
• A library written in one programming language may be used in another language if
bindings are written; TK is integrated with the TCL language. Various other languages
have bindings for TK, a partial list of which is on the TK website. Bindings exist for
additional languages which might not be listed, including Ada (called TASH),Haskell
(called HTK), Perl, Python (called TK inter), Ruby, Rex, and Common Lisp.
• There are several ways to use TK from Perl: the TCL::TK and TKX, Perl, both of which
use TCL as a bridge to access TK, and Perl/TK, which provides native Perl access to
TK structures. The Python binding uses TCL as a bridge to TK.
4
ABOUT FILE HANDLING:
File handling is an integral part of programming. File handling in Python is simplified with
built-in methods, which include creating, opening, and closing files.
While files are open, Python additionally allows performing various file operations, such as
reading, writing, and appending information.
TYPES OF FILES:
Text File:
Computers store every file as a collection of 0s and 1s i.e., in binary form. Therefore, every file
is basically just a series of bytes stored one after the other. There are mainly two types of data
files — text file and binary file. A text file consists of human readable characters, which can be
opened by any text editor. On the other hand, binary files are made up of non-human readable
characters and symbols, which require specific programs to access its contents. 2.2.1 Text file
A text file can be understood as a sequence of characters consisting of alphabets, numbers and
other special symbols. Files with extensions like .txt, .py, .csv, etc. are some examples of text
files. When we open a text file using a text editor (e.g., Notepad), we see several lines of text.
However, the file contents are not stored in such a way internally. Rather, they are stored in
sequence of bytes consisting of 0s and 1s. In ASCII, UNICODE or any other encoding scheme,
the value of each character of the text file is stored as bytes. So, while opening a text file, the
text editor translates each ASCII value and shows us the equivalent character that is readable
by the human being. For example, the ASCII value 65 (binary equivalent 1000001) will be
displayed by a text editor as the letter ‘A’ since the number 65 in
ASCII character set represents ‘A’. Each line of a text file is terminated by a special character,
called the End of Line (EOL). For example, the default EOL character in Python is the newline
(\n). However, other characters can be used to indicate EOL. When a text editor or a program
interpreter encounters the ASCII equivalent of the EOL character, it displays the remaining file
contents starting from a new line. Contents in a text file are usually separated by whitespace,
but comma (,) and tab (\t) are also commonly used to separate values in a text file.
5
Binary File:
A binary file is a file whose content is in a binary format consisting of a series of sequential
bytes, each of which is eight bits in length. The content must be interpreted by a program or a
hardware processor that understands in advance exactly how that content is formatted and how
to read the data. Binary files include a wide range of file types, including executables, libraries,
graphics, databases, archives and many others. Electronic files are typically categorized as
either binary files or text files. It could be argued that text files are also a type of binary file
because, like any electronic file, they're made up of sequences of bytes. However, the two are
generally considered to be different types.
Text files are in a human-readable format and typically adhere to specific character sets, such
as Unicode.
➢ Pickle refers to the process of converting Python objects (like lists, dictionaries, etc.)
into a byte stream that can be saved to a file. .pkl is just the file extension for files that
store serialized Python objects.
CSV File:
A CSV file (Comma Separated Values file) is a type of plain text file that uses specific
structuring to arrange tabular data. Because it’s a plain text file, it can contain only actual text
data—in other words, printable ASCII or Unicode characters.
The structure of a CSV file is given away by its name. Normally, CSV files use a comma to
separate each specific data value.
6
PROJECT DESCRIPTION:
Objective:
The objective of this project is to let the students apply the programming knowledge into a
realworld situation/problem and exposed the students how programming skills helps in
project, requiring writing and presentation skills which exemplify scholarly style in
computer science.
Description:
The Olympiad Module is a Python-based application developed using the `Tkinter` library for
creating a graphical user interface (GUI). The module is designed for organizing an
Olympiadstyle quiz competition where students can take quizzes, and teachers can manage
questions and view results. The application supports different types of questions, including
multiple-choice, fill-in-the-blank, and true/false questions. The data, such as questions and
results, are saved and loaded from binary files using the `pickle` module.
7
Features:
1. Teacher's Dashboard:
- Teachers can access the dashboard after entering a valid password.
- Teachers can add new questions in different formats: Multiple-choice (MCQ), Fill-in-
theBlank (FIB), and True/False (T/F).
- Teachers can view the results of student attempts.
2. Student Interface:
- Students can take the quiz after entering their name.
- Students answer questions, and their scores are tracked.
- Once all questions are answered, the student's final score is displayed.
3. Data Storage:
- Questions and results are saved in binary files (`questions.pkl` and `results.pkl`), using
the `pickle` module.
- The data is loaded when the application starts and saved back to the files after each
modification or quiz completion.
How It Works:
- Upon launching the application, the main menu is displayed, offering options for
teachers and students.
- Teachers can manage the quiz by adding questions or viewing results, while students
can attempt the quiz after entering their name.
- Questions are loaded from the saved file at the start of the quiz, and the student's
answers are evaluated in real time. The score is updated and displayed at the end of the quiz.
8
Usage of data
1. Loading Data:
- On startup, the application checks for existing `questions.pkl` and `results.pkl` files. If they
exist, the data is loaded into memory; otherwise, empty data structures are initialized.
2. Saving Data:
- Every time a question is added or a student's results are updated, the corresponding data is
serialized and saved back to the respective `.pkl` files.
3. Managing Quiz:
- The quiz is dynamic, with the application displaying questions and recording answers.
The flow proceeds through the questions in sequence, and once all questions are answered, the
student's score is recorded and displayed.
MODULES:
The important modules used in the project are as follows:
• Login page
• Teachers dashboard
• Student interface
• Add questions
• Result viewing
• Score viewing
9
SOFTWARE SPECIFICATION:
Operating System : Windows10
Platform : Python IDLE 3.12
Language : Python
SOURCE CODE:
import tkinter as tk
from tkinter import simpledialog, messagebox
import pickle import os
class OlympiadModule:
def __init__(self, root):
self.root = root
self.root.title("Olympiad Module")
self.questions_file = "questions.pkl"
self.results_file = "results.pkl"
self.password = "123" # Password for teacher access
self.load_data()
self.main_menu()
def load_data(self):
if os.path.exists(self.questions_file):
with open(self.questions_file, 'rb') as file:
self.questions = pickle.load(file)
else:
self.questions = []
10
if os.path.exists(self.results_file):
with open(self.results_file, 'rb') as file:
self.results = pickle.load(file)
else:
self.results = []
def save_data(self): with
open(self.questions_file, 'wb') as file:
pickle.dump(self.questions, file)
def prompt_password(self):
password = simpledialog.askstring("Password", "Enter teacher password:", show="*")
if password == self.password:
11
self.teacher_menu()
else:
messagebox.showerror("Error", "Incorrect password!")
def teacher_menu(self): for widget in
self.root.winfo_children():
widget.destroy()
def choose_question_type(self):
question_type = simpledialog.askstring("Question Type", "Enter question type (mcq /
fib / t/f):") if question_type == "mcq":
self.add_question()
elif question_type == "fib":
self.add_fill_in_the_blank_question()
elif question_type == "t/f":
self.add_true_false_question()
else:
12
messagebox.showerror("Error", "Invalid
question type!")
def add_question(self):
question = simpledialog.askstring("Input", "Enter the question:")
if not question:
messagebox.showerror("Error", "Question cannot be empty!")
return
choices = []
for i in range(4):
choice = simpledialog.askstring("Input", f"Enter choice {i+1}:")
if not choice:
messagebox.showerror("Error", "All choices must be filled!")
return
choices.append(choice)
def add_fill_in_the_blank_question(self):
question = simpledialog.askstring("Input", "Enter the question with a blank (use _ for
blank):") if not question:
messagebox.showerror("Error", "Question cannot be empty!")
return
13
answer = simpledialog.askstring("Input", "Enter the correct answer:")
if not answer:
messagebox.showerror("Error", "Answer cannot be empty!")
return
def add_true_false_question(self):
question = simpledialog.askstring("Input", "Enter the true/false question:")
if not question:
messagebox.showerror("Error", "Question cannot be empty!")
return
14
title = tk.Label(self.root, text="Results", font=("Helvetica", 16), pady=20,
bg='lightgreen') title.pack()
self.current_question_index = 0
self.score = 0 self.show_question()
15
if self.current_question_index >= len(self.questions):
self.finish_quiz()
return
question_data = self.questions[self.current_question_index]
question_label = tk.Label(self.root, text=question_data["question"], font=("Helvetica",
14), pady=20, bg='lightblue')
question_label.pack()
if question_data["type"] == "multiple-choice":
self.selected_answer = tk.StringVar()
for choice in question_data["choices"]:
choice_btn = tk.Radiobutton(self.root, text=choice, variable=self.selected_answer,
value=choice, font=("Helvetica", 12), bg='lightblue') choice_btn.pack(anchor='w')
16
false_btn = tk.Radiobutton(self.root, text="False", variable=self.selected_answer,
value="false", font=("Helvetica", 12), bg='lightblue') false_btn.pack(anchor='w')
def submit_answer(self):
selected = self.selected_answer.get()
if selected:
question_data = self.questions[self.current_question_index]
correct_answer = question_data["correct_answer"]
# Case-insensitive comparison if
selected.lower() == correct_answer.lower():
self.score += 1
print(f"Score updated: {self.score}") # Debugging the score
self.current_question_index += 1
self.show_question() else:
messagebox.showwarning("Warning", "Please select an answer!")
def submit_fill_in_the_blank_answer(self):
answer = self.answer_entry.get().strip() if
answer:
correct_answer = self.questions[self.current_question_index]["correct_answer"]
if answer.lower() == correct_answer.lower():
17
self.score += 1
print(f"Score updated: {self.score}") # Debugging the score
self.current_question_index += 1
self.show_question() else:
messagebox.showwarning("Warning", "Please enter an answer!")
self.main_menu()
if __name__ == "__main__":
root = tk.Tk()
app = OlympiadModule(root)
root.mainloop()
18
SAMPLE OUTPUT:
HOME PAGE:
19
TEACHER’S DASHBOARD:
20
21
22
23
24
25
26
27
STUDENT INTERFACE:
28
29
30
VIEWING RESULT:
31
VIEWING QUESTION AND RESULT IN
BINARY FILE:
32
VIEWING ANSWERS OF STUDENT IN
PYTHON SHELL:
33
CONCLUSION:
“Olympiad module in Python is a great asset for accessing and manipulating data directly into
your Python program using tkinter. Unlike other programming languages, python is
uncomplicated & pretty straightforward and as already said, can help you save a lot of time.
With that said, one can try exploring a few more operations and methods associated with
Olympiad module to make their tasks more efficient and productive. Python is pretty easy
because most of the basic operations just take a single line of code to do the job.
The Olympiad Module is a comprehensive and user-friendly Python application designed for
educational purposes. It allows teachers to efficiently manage quizzes by adding various types
students to participate in quizzes and track their progress. The use of `Tkinter` ensures an
intuitive graphical interface, providing smooth navigation and interaction for both teachers and
students. Data is stored in binary files using the `pickle` module, allowing easy saving and
This design facilitates a seamless experience, with teachers having full control over the quiz
content and the ability to view student results. Students, on the other hand, can take the quizzes,
have their answers evaluated in real-time, and receive instant feedback with their final score.
The system is structured to be scalable and flexible, with the potential for future enhancements,
such as integrating more question types or supporting a larger number of users. While the
current implementation is ideal for local environments, transitioning to more secure and
scalable data storage solutions could further enhance the application's robustness in the future.
Overall, the Olympiad Module is an effective tool for conducting interactive quizzes in
educational settings.
34
INSTALLATION PROCEDURE:
Install Python from web
35
BIBLIOGRAPHY:
1. Computer science With Python - Class XII By: Sumita Arora
3. Website:https://www.geeksforgeeks.org/python-quiz-project/
4. Website:https://codewithcurious.com/projects/quiz-using-python
5. https://stackoverflow.com
36