CS Project 12 RRS
CS Project 12 RRS
CLASS - XII
COMPUTER SCIENCE(083)
PROJECT WORK
TITLE : RAILWAY RESERVATION
SYSTEM
SUBMITTED BY:
ROLL NO.: ----------------------------
NAME : SURJADEEP SAHA
CLASS : XII – A
DATE : ----------------------------
Signature Signature
(Internal Examiner) (External Examiner)
1
CERTIFICATE
2
ACKNOWLEDGEMENT
3
CONTENTS
Page
S.No. Title
No.
1 Introduction 5-8
8 Soft Copy 28
4
INTRODUCTION
5
or open
“https://dev.mysql.com/downloads/connector/python/
”and download connector as per OS and Python
version.
5. Importing mysql.connector
import mysql.connector
Or
import mysql.connector as ms
Here “ms” is an alias, so every time we can use
“ms” in place of “mysql.connector”.
6
6. Open a connection to MySQL Database
To create connection, connect() function is used.
Its syntax is:
connect(host=<server_name>,user=<user_na
me>,passwd=<password>[,database=<datab
ase>])
Here server_name means database servername,
generally it is given as “localhost”.
User_name means user by which we connect with
MySQL , generally it is given as “root”.
Password is the password of user “root”.
Database is the name of database whose
data(table) we want to use.
7. Creating Cursor
It is a useful control structure of database
connectivity.
When we fire a query to database, it is executed
and result-set(set of records) is sent over the
connection in one go.
While we may want to access data one row at a
time, query processing itself does not occur row by
row, so cursor helps us in performing this task.
Cursor stores all the data as a temporary container
of returned data and we can fetch data one row at
a time from Cursor.
7
8. Creating Cursor and Executing Query
TO CREATE CURSOR
Cursor_name = connectionObject.cursor()
For e.g.
mycursor = mycon.cursor()
TO EXECUTE QUERY
We use execute() function to send query to
connection.
Cursor_name.execute(query)
For e.g.
mycursor.execute(‘select * from emp’)
8
ABOUT THE PROJECT
1. Introduction
This Indian Railway Reservation System project is a
Python-based application designed to simulate ticket
reservation, cancellation, and PNR status checking. This
project demonstrates how programming can simplify
and automate a complex, real-world process, providing
an effective solution for managing railway reservations.
2. Objective
The primary objective is to create a system that allows
users to book tickets, check reservation status, and
cancel tickets through a simple command-line
interface. This project also aims to showcase the
integration of Python with MySQL to handle backend
data storage securely and efficiently.
3. Modules and Libraries Used
mysql.connector: This module is crucial for
establishing a connection between Python and the
MySQL database. It allows executing SQL queries
from within the Python program.
9
random: Used to generate unique PNR numbers
for passengers, adding an element of uniqueness
to each reservation.
4. Database and Table Structure
The MySQL database, named Railway_System, is
created to store train and passenger data. The project
includes two main tables:
Train_details: Stores information about available
trains, including train name, train number, and
seat availability by class.
Passengers: Stores reservation details, such as
passenger name, age, source and destination
stations, date of journey, train number, number of
passengers, chosen class, fare, booking status, and
PNR number.
5. Python-MySQL Connectivity
The project uses Python-MySQL connectivity to
interact with the MySQL database:
Connection: mydb = mysql.connector.connect() is
used to connect to the MySQL server.
Cursor: mycursor = mydb.cursor() enables the
execution of SQL commands through Python.
SQL Execution: SQL queries are executed via
mycursor.execute() to create tables, insert data,
update reservations, and retrieve passenger data.
10
6. Functions and Logic Implementation
The project is function-based, which makes it modular
and organized. Key functions include:
dataBase(): Checks for the existence of the
database and creates it if absent. It also initiates
the main menu.
Tables(): Creates the necessary tables for storing
train and passenger information.
railresmenu(): Displays the main menu with
options to access the database, create tables,
reserve or cancel tickets, check PNR status, and
exit.
reservation(): Handles the ticket reservation
process, including passenger details input, seat
selection, fare calculation, and ticket status
assignment.
cancel(): Allows users to cancel a reserved ticket
by updating the PNR status to "Cancelled" in the
database.
displayPNR(): Retrieves and displays the details of
a specific PNR from the Passengers table.
7. Programming Elements Used
Loops:
o The while loop in the reservation() function
11
Conditionals:
o If-elif-else structures are used throughout the
12
SOURCE CODE
13
CODE FOR THE PROJECT
14
15
16
17
SAMPLE RUN
WELCOMING MESSAGE AND MAIN MENU
ACCESSING DATABASE
18
CREATING TABLES AND INSERTING VALUES INTO
THE “TRAIN DETAILS” TABLE
RESERVATION OF TICKET
1.
2.
19
20
CANCELLATION OF TICKET
21
2.
22
DETAILS STORED IN MySQL
VIA CONNECTIVITY WITH
PYTHON
TABLES CREATED
23
RECORDS IN THE TABLE “TRAIN DETAILS”
24
SUGGESTIONS FOR
IMPROVEMENT
25
6. User Authentication and Profiles: Add a feature for user
registration and login, enabling users to save their booking
history and retrieve past records easily.
7. Random Module for Reservation Status: In addition to
random.choice() for status selection, consider customizing
the probability so that "Confirmed" appears more often
when seats are available, and "Waiting" is selected more
when seat availability is low.
8. User Authentication and Profiles: Add a feature for user
registration and login, enabling users to save their booking
history and retrieve past records easily. This would improve
the usability and user experience of the system.
9. Interactive Graphical User Interface (GUI): For a more
user-friendly experience, you could create a GUI using
libraries such as Tkinter or PyQt. This would make the system
visually appealing and easier for non-technical users to
navigate.
26
BIBLIOGRAPHY
For successfully completing my project,I have taken
help from the following books :
COMPUTER SCIENCE WITH PYTHON – BY SUMITA
ARORA,CLASS XII,2024 EDITION
COMPUTER SCIENCE WITH PYTHON – BY PREETI
ARORA,CLASS XII,2020 EDITION
MODERN PYTHON COOKBOOK,THIRD EDITION
27
SOFT COPY
THE SOFT COPY OF THE PROJECT
AND THE PYTHON PROGRAM CAN
BE ACCESSED BY THIS CD :
28
29