INDEX
1.) CERTIFICATE
2.) ACKNOWLEDGEMENT
3.) DECLARATION
4.) AIM / EXPERIEMNTS
5.) CODING WITH SCREENSHOTS
6.) REQUIREMENTS
7.) BIBLIOGRAPHY
CERTIFICATE
This is to certify that Somesh Raj has
successfully completed the project
report entitled “Railway Reservation
System” during the academic year
2025-2026, towards partial fulfilment
of the Computer Science Practical
Examination conducted by CBSE.
The project work submitted by the
student is original and has been
completed under the prescribed
guidelines of the board.
ACKNOWLEDGEMENT
I take this opportunity to express my
profound gratitude and deep regards to my
Computer Science teacher for his
exemplary guidance, constant monitoring,
and continuous encouragement throughout
the course of this project.
The support, help, and guidance provided
by him from time to time have been
invaluable and shall carry me a long way
in the journey of life on which I am about
to embark.
I am also thankful to my school for
providing the necessary facilities and
resources to complete this project
successfully.
— Somesh Raj
DECLARATION
I hereby declare that the project work
entitled "Railway Reservation System"
has been prepared by me, Somesh Raj,
under the supervision of our subject
teacher. This work is submitted for the
partial fulfilment of the requirements for
the All India Senior Secondary
Certificate Examination (AISSCE).
Signature of the Candidate:
____________________
Name: Somesh Raj
Roll No:____________________
Date: ____________________
REQIREMENTS
Software & Hardware Requirements
To ensure the smooth execution of this
project, the following configurations were
utilized:
Programming Language: Python 3.3
or higher
Integrated Development
Environment (IDE): Python IDLE
Operating System: Windows / macOS
/ Linux
Minimum Hardware Specs: * RAM:
128 MB (Minimum)
o Processor: Intel Core i3 or
equivalent
Bibliography
The following resources were consulted
during the research, development, and
documentation phases of this project:
Books & Publications
Computer Science with Python (Class
XI) – Sumita Arora
Computer Science with Python (Class
XII) – Sumita Arora
Web Resources
GitHub: For version control concepts
and open-source code references.
StackExchange / StackOverflow: For
troubleshooting logic and debugging.
Official Python Documentation:
[Link]
Submitted By: Somesh Raj
INTRODUCTION
This project introduces railway reservation
system. It explains how reservation is being
done in Indian Railways. The step by step
procedure is explained.
Proper comments have been given at desired
location to make the project user friendly.
Various functions and structures are used to
make a complete use of this language, this
project is well versed with the programming.
Railway reservation can easily accompany
with the help of this.
ABOUT PYTHON
Python is a high level, object-oriented programming language. It was
developed in 1991 by Guido Van Rossum. Its syntax is similar to the
English Language and that is why it enhances code readability. It uses
indentation for defining scopes of loops, if-else constructs, classes,
etc.
Key Features and Uses:
Python Logo - File Handling in Python: A core part of
learning Python involves understanding how to store and
retrieve data.
Server-Side Applications: Python can be used to create robust
server-side applications.
Task Automation: It helps to perform task automation through
efficient scripting.
Stand-alone Applications: Python is widely used to create
stand-alone desktop applications.
Modern Technologies: Python is heavily used in Big Data,
Data Science, Machine Learning, and Artificial Intelligence.
Actually, the list can go on and on. This defines the power of Python
as a programming language. Hence it becomes very important to learn
how to write to a file using Python and then read from the same file.
Integration with MySQL:
"For this project, Python acts as the Front-end and MySQL acts as the
Back-end. We use the mysql-connector-python library to establish a
bridge between the two. This allows our Python program to send SQL
queries to the database, enabling permanent data storage for train and
passenger records. This connectivity is essential for real-world
applications where data must persist even after the program is closed."
Python is an interpreted, object-oriented, high-level programming
language with dynamic semantics. Its high-level built in data
structures, combined with dynamic typing and dynamic binding,
make it very attractive for Rapid Application Development, as well as
for use as a scripting or glue language to connect existing components
together.
Python's simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance. Python supports
modules and packages, which encourages program modularity and
code reuse. The Python interpreter and the extensive standard library
are available in source or binary form without charge for all major
platforms, and can be freely distributed.
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.
On the other hand, often the quickest way to debug a program is to
add a few print statements to the source: the fast edit-test-debug cycle
makes this simple approach very effective.
A recent survey established the Python language to be the fifth most
popular, behind JavaScript, SQL, Java, and C#. According to the 2017
Stack Overflow survey, nearly 32% of developers use it, and a further
20% want to do so. The usage is up from 22% reported in the first
Stack Overflow survey, which ran in 2013.
The survey also reports Python to be the sixth most loved language
(behind Rust, Smalltalk, TypeScript, Swift, and Go), and I think it's
interesting to note that Python is the top language that is both used
and loved. (the other languages that are loved are mostly aspirational,
for example, TypeScript is used by just 9.5% of people, while Rust
and Smalltalk aren't even on the scale).
There are more than 147,000 packages in the package repository
(colloquially known as the Cheese Shop), which are what make it so
versatile, and so popular. You can use Python for everything from web
development, to data science and data visualisation, to games
development, and DevOps, without having to start at ground zero and
implement your own code for everything.
With so many packages available, we are seeing, in particular, a huge
uptake in those used for AI and data science projects.
Python is a super fun language which can brings a level of excitement
and ease to programming like no other language can.
Section 2: File Handling in Python
FILE HANDLING IN PYTHON
If you are working in a large software application where they process
a large number of data, then we cannot expect those data to be stored
in a variable as the variables are volatile in nature. Hence when are
you about to handle such situations, the role of files will come into the
picture.
As files are non-volatile in nature, the data will be stored permanently
in a secondary device like Hard Disk and using python we will handle
these files in our applications.
Python too supports file handling and allows users to handle files i.e.,
to read and write files, along with many other file handling options, to
operate on files. The concept of file handling has stretched over
various other languages, but the implementation is either complicated
or lengthy, but alike other concepts of Python, this concept here is
also easy and short. Python treats file differently as text or binary and
this is important. Each line of code includes a sequence of characters
and they form text file. Each line of a file is terminated with a special
character, called the EOL or End of Line characters like comma (,) or
newline character. It ends the current line and tells the interpreter a
new one has begun. Let's start with Reading and Writing files.
Working of open() function:
Section 3: The open() Function Syntax and Modes
We use open () function in Python to open a file in read or write
mode. As explained above, open () will return a file object. To return a
file object we use open() function along with two arguments, that
accepts file name and the mode, whether to read or write. So, the
syntax being: open(filename, mode). There are three kinds of mode,
that Python provides and how files can be opened:
“ r “, for reading.
“ w “, for writing.
“ a “, for appending.
“ r+ “, for both reading and writing
One must keep in mind that the mode argument is not mandatory. If
not passed, then Python will assume it to be “ r ” by default.
There are also various other functions that help to manipulate the files
and its contents. One can explore various other functions in Python
Docs.
ABOUT MODULES
Modules refer to a file containing Python statements and definitions.
A file containing Python code, for e.g.: [Link], is called a module
and its module name would be example.
We use modules to break down large programs into small manageable
and organized files. Furthermore, modules provide reusability of
code.
We can define our most used functions in a module and import it,
instead of copying their definitions into different programs. We can
import the definitions inside a module to another module or the
interactive interpreter in Python. We use the import keyword to do
this.
Python has a ton of standard modules available. Standard modules can
be imported the same way as we import our user-defined modules.
Some advantages of modules are:
1. Division of development
2. Increases readability of program
3. Programming errors can easily be detected
4. Allows reuse of code
5. Improves manageability
6. Collaboration in projects made efficient and easy
Section 4: About Indian Railway
ABOUT INDIAN RAILWAY
Indian Railways is the state-owned railway company of India; it has a
complete monopoly over the country's rail transport. Indian Railways
(IR) has one of the largest and busiest rail networks in the world,
transporting over 5 billion passengers and over 350 million tonnes of
freight annually. IR is also the world's largest commercial or utility
employer, having more than 1.6 million regular employees on its
payroll.
Railways were first introduced to India in 1853, and by 1947, the year
of India's independence, it had grown to forty-two rail systems. In
1951 the systems were nationalised as one unit, to become one of the
largest networks in the world. Indian Railways operates both long
distances, as well as suburban rail systems. It operates 8,702
passenger trains and transports around five billion annually across
twenty-seven states and three union territories (Delhi, Puducherry and
Chandigarh). Sikkim is the only state not connected. The Railway
Budget deals with the induction and improvement of existing trains
and routes, the modernisation and most importantly the tariff for
freight and passenger travel.
Due to the huge magnitude of the spread of IR, the system cannot
sustain without computers, which have programs built for its smooth
functioning. This project deals with the Indian Railways and presents
a system to digitize the system.
# --- DATABASE CONNECTION FUNCTION ---
def create_connection():
try:
connection = [Link](
host='localhost',
user='root', # YOUR MYSQL USERNAME
password='password', # YOUR MYSQL PASSWORD
database='railway_db'
)
if connection.is_connected():
return connection
except Error as e:
print(f"Error: {e}")
return None
# --- FUNCTION: ADD NEW TRAIN ---
def add_train():
conn = create_connection()
if conn:
cursor = [Link]()
print("\n--- ENTER TRAIN DETAILS ---")
tno = int(input("Enter Train Number: "))
tname = input("Enter Train Name: ")
source = input("Source Station: ")
dest = input("Destination Station: ")
fare = int(input("Enter Ticket Fare: "))
query = "INSERT INTO trains (tno, tname, source, destination, fare)
VALUES (%s, %s, %s, %s, %s)"
[Link](query, (tno, tname, source, dest, fare))
[Link]()
print(">> Train Added to Database Successfully!")
[Link]()
# --- FUNCTION: BOOK A TICKET ---
def book_ticket():
conn = create_connection()
if conn:
cursor = [Link]()
print("\n--- PASSENGER BOOKING ---")
pname = input("Enter Passenger Name: ")
age = int(input("Enter Age: "))
tno = int(input("Enter Train Number to Book: "))
# Check if train exists before booking
[Link]("SELECT * FROM trains WHERE tno = %s", (tno,))
if [Link]():
query = "INSERT INTO passengers (pname, age, tno, status)
VALUES (%s, %s, %s, 'CONFIRMED')"
[Link](query, (pname, age, tno))
[Link]()
print(f">> Ticket Booked for {pname}!")
else:
print(">> Error: Train Number not found!")
[Link]()
# --- FUNCTION: VIEW RECORDS ---
def view_all_trains():
conn = create_connection()
if conn:
cursor = [Link]()
[Link]("SELECT * FROM trains")
rows = [Link]()
print("\n{:<10} {:<20} {:<15} {:<15} {:<10}".format('T-No', 'Name',
'From', 'To', 'Fare'))
print("-" * 70)
for row in rows:
print("{:<10} {:<20} {:<15} {:<15} {:<10}".format(row[0], row[1],
row[2], row[3], row[4]))
[Link]()
def view_bookings():
conn = create_connection()
if conn:
cursor = [Link]()
[Link]("SELECT * FROM passengers")
rows = [Link]()
print("\n--- PASSENGER LIST ---")
for row in rows:
print(f"Name: {row[0]} | Age: {row[1]} | Train No: {row[2]} | Status:
{row[3]}")
[Link]()
# --- MAIN MENU ---
def main_menu():
while True:
print("\n======================================")
print(" RAILWAY RESERVATION SYSTEM (V1.0)")
print("======================================")
print("1. Add New Train Details")
print("2. Book a Ticket")
print("3. View Available Trains")
print("4. View All Bookings")
print("5. Exit")
choice = input("Enter Choice (1-5): ")
if choice == '1': add_train()
elif choice == '2': book_ticket()
elif choice == '3': view_all_trains()
elif choice == '4': view_bookings()
elif choice == '5':
print("Thank you for using the system!")
break
else: print("Invalid option! Please try again.")
if __name__ == "__main__":
main_menu()
4. MySQL Backend Commands (The Foundation)
You must run these in your MySQL Command Line Client first:
SQL
CREATE DATABASE railway_db;
USE railway_db;
CREATE TABLE trains (
tno INT PRIMARY KEY,
tname VARCHAR(50),
source VARCHAR(30),
destination VARCHAR(30),
fare INT
);
CREATE TABLE passengers (
pname VARCHAR(50),
age INT,
tno INT,
status VARCHAR(20),
FOREIGN KEY (tno) REFERENCES trains(tno)
);