0% found this document useful (0 votes)
45 views29 pages

CS Project 12 RRS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views29 pages

CS Project 12 RRS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

AISSCE 2024 - 25

CLASS - XII
COMPUTER SCIENCE(083)
PROJECT WORK
TITLE : RAILWAY RESERVATION
SYSTEM

PM SHRI KENDRIYA VIDYALAYA,


NEW BONGAIGAON

SUBMITTED BY:
ROLL NO.: ----------------------------
NAME : SURJADEEP SAHA
CLASS : XII – A
DATE : ----------------------------

Signature Signature
(Internal Examiner) (External Examiner)

1
CERTIFICATE

This is to hereby certify that the original and genuine


project has been completed sincerely and satisfactorily
by SURJADEEP SAHA(Roll No.: ----------------------------) of class XII
- A , PM SHRI KENDRIYA VIDYALAYA , NEW
BONGAIGAON , regarding his project entitled
“RAILWAY RESERVATION SYSTEM” under the guidance
of Mr. AMIT KUMAR PANDEY , PGT Computer Science
for the fulfillment of requirement of AISSCE – 2025
Practical Examination in the subject Computer
Science(083).

Internal Examiner External Examiner

2
ACKNOWLEDGEMENT

I would sincerely like to express my deep sense of


gratitude and indebtedness to our learned teacher
Mr. AMIT KUMAR PANDEY , PGT Computer Science
for his invaluable help,advice and guidance in the
preparation of this project.

I am also greatly indebted to our principal Mr. VISHAL


KHARE and school authorities for providing me with
the facilities and requisite laboratory conditions for my
project file.

I also extend my thanks to my parents and friends who


helped me to complete this project file successfully.

DATE : SURJADEEP SAHA


------------------------- XII – A

3
CONTENTS

Page
S.No. Title
No.

1 Introduction 5-8

2 About The Project 9 - 12


3 Source Code 13 - 17
4 Sample Run 18 - 22
Details Stored In MySQL
5 Via Connectivity With 23 - 24
Python
Suggestions for
6 25 -26
Improvement
7 Bibliography 27

8 Soft Copy 28

4
INTRODUCTION

Connecting Python application with MySQL

1. Every application requires data to be stored for


future reference to manipulate data. Today every
application stores data in database for this
purpose.
2. Python allows us to connect all types of database
like Oracle, SQL Server, MySQL.
3. Before we connect python program with any
database like MySQL we need to build a bridge to
connect Python and MySQL.

To build this bridge so that data can travel both


ways we need a connector called
“mysql.connector”.
We can install “mysql.connector” by using
following methods:
At command prompt (Administrator login),
Type “pip install mysql-connector-python” and
press enter (internet connection is required).This
connector will work only for MySQL 5.7.1 or later

5
or open
“https://dev.mysql.com/downloads/connector/python/
”and download connector as per OS and Python
version.

4. Once the connector is installed you are ready to


connect your python program to MySQL.
The following steps to follow while connecting
your python program with MySQL:
 Open Python
 Import the package required (import
mysql.connector)
 Open the connection to database
 Create a cursor instance
 Execute the query and store it in result-set
 Extract data from result-set
 Clean up the environment

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

ensures that the user enters a valid train


number from the available options.

11
 Conditionals:
o If-elif-else structures are used throughout the

program, such as in reservation() to determine


the selected class and calculate the
appropriate fare.
 Data Insertion:
o SQL INSERT commands are used to store

passenger data in the Passengers table.


 Randomization:
o The random.randint() function creates unique

PNR numbers for each booking, ensuring each


reservation is identifiable.
o The random.choice() function is used to

assign a ticket status randomly between


"Confirmed" and "Waiting", simulating real-
world booking uncertainty.

12
SOURCE CODE

CODE FOR CONNECTING MySQL WITH PYTHON


APPLICATION AND CREATING DATABASE AND TABLES

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

DISPLAY PNR STATUS


1.

21
2.

QUITTING THE RAILWAY RESERVATION SYSTEM

22
DETAILS STORED IN MySQL
VIA CONNECTIVITY WITH
PYTHON
TABLES CREATED

23
RECORDS IN THE TABLE “TRAIN DETAILS”

RECORDS IN THE TABLE “PASSENGERS”

24
SUGGESTIONS FOR
IMPROVEMENT

1. Multiple Passenger Details: Enhance the system to collect


individual details for each passenger in a booking involving
multiple travellers. This could involve asking for each
passenger’s name, age, and seat preferences,etc., mirroring
the data collected for the primary passenger.
2. Dynamic Fare Calculation: Introduce a fare calculation
algorithm that takes into account travel distance, train type,
and seasonal variations. This would make the system more
accurate and realistic, as fares differ based on journey length
and demand.
3. Seat Availability Tracking: Implement a feature to
dynamically update seat availability for each class based on
bookings and cancellations, ensuring that seat inventory
remains accurate and up-to-date.
4. Enhanced PNR Status Tracking: Integrate real-time PNR
status updates using actual data for train schedules and
bookings (if connected to an actual railway server or
database). This would provide users with more accurate and
current information on ticket status.
5. Print Tickets: Add functionality to allow users to print their
tickets upon booking confirmation, which would align with
real-world practices in railway reservations.

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

For successfully completing my project,I have taken


help from the following websites :
 https://www.geeksforgeeks.org/
 https://docs.python.org/3/
 https://www.w3schools.com/python/

27
SOFT COPY
THE SOFT COPY OF THE PROJECT
AND THE PYTHON PROGRAM CAN
BE ACCESSED BY THIS CD :

28
29

You might also like