0% found this document useful (1 vote)
119 views

The Baptist Convent Senior Secondary School: Project File

The document describes a railway reservation system project created in Python. It includes modules for train details, ticket reservation, cancellation, displaying PNR status and tickets. The project uses a MySQL database to save user data and retrieve it. It allows users to view train schedules, reserve tickets in different classes, check PNR status and print tickets. Python and modules like MySQL connector are used to connect the application to the database.

Uploaded by

League YT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
119 views

The Baptist Convent Senior Secondary School: Project File

The document describes a railway reservation system project created in Python. It includes modules for train details, ticket reservation, cancellation, displaying PNR status and tickets. The project uses a MySQL database to save user data and retrieve it. It allows users to view train schedules, reserve tickets in different classes, check PNR status and print tickets. Python and modules like MySQL connector are used to connect the application to the database.

Uploaded by

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

THE BAPTIST CONVENT SENIOR

SECONDARY SCHOOL

Computer Science
[Python]

PROJECT FILE
Railway Reservation System

Submitted By Submitted to:


Name Bhavya Kawatra Raman Deep Singh
Class XII
Roll No.
Certificate
I hereby certify that this Project File has been made in
partial fulfilment of the requirements for the practical
exam of Class XII Computer Science as a part of
A.I.S.S.C.E(2019-2020) and is an authentic record of my
own work carried out under the supervision of Mr.
Raman Deep Singh.

Bhavya Kawatra

This is to certify that the above statement made by the


candidate is correct and true to the best of my
knowledge.

Principal
Mr. Raman Deep Singh
The Baptist Convent School
(Computer Science Teacher)
Patparganj, Delhi
Acknowledgment
Acknowledgement is the most important part of this Project
File as it provides me an opportunity to express my gratitude
towards the Almighty, my Parents and my Teachers.

I have made this project under the guidance of my computer


science teacher, Mr. Raman Deep Singh, who made the
resources available at right time and provided valuable insights
which lead to the successful completion of my Project File.

I am greatly thankful to him for spending his precious time in


testing and debugging my project. I also thank my Parents
without whose mental support this file would not have been
completed.

And sincere thanks to the Almighty who is always showering his


blessings on us.

Bhavya kawatra
Python Introduction
Python is a popular programming language. It was created by Guido van Rossum,
and released in 1991.

It is used for:

• web development (server-side),


• software development,
• mathematics,
• system scripting.

Python can do following

• Python can be used on a server to create web applications.


• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and modify files.
• Python can be used to handle big data and perform complex mathematics.
• Python can be used for rapid prototyping, or for production-ready software
development.

Advantages of Python

• Python works on different platforms (Windows, Mac, Linux, Raspberry Pi,


etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be executed
as soon as it is written. This means that prototyping can be very quick.
• Python can be treated in a procedural way, an object-orientated way or a
functional way.
Python can be used in database applications.One of the most popular databases is
MySQL. Python needs a MySQL driver to access the MySQL database.

Arguments required to connect MySQL from Python

We need to know the following detail of the MySQL server to perform the
connection from Python.

• Username – i.e., the username that you use to work with MySQL Server. The
default username for the MySQL database is a root
• Password – Password is given by the user at the time of installing the MySQL
database. If you are using root then you won’t need the password.
• Host Name – is the server name or Ip address on which MySQL is running. if
you are running on localhost, then you can use localhost, or it’s IP, i.e.
127.0.0.0
• Database Name – Database name to which you want to connect. Here we
are using Database named ‘Electronics‘ because we have already created
this for our example.

Steps to connect MySQL database in Python using MySQL Connector Python

1. Install MySQL Connector Python using pip.


2. Use the mysql.connector.connect() method of MySQL Connector Python
with required parameters to connect MySQL.
3. Use the connection object returned by a connect() method to create
a cursor object to perform Database Operations.
4. The cursor.execute() to execute SQL queries from Python.
5. Close the Cursor object using a cursor.close() and MySQL database
connection using connection.close() after your work completes.
6. Catch Exception if any that may occur during this process.
Railway Reservation System
Abstract
Railway Reservation System project is written in Python. The project file contains
a python script (railwayreservation1234.py). This is a simple console based system
which is very easy to use and understand. Talking about the system, it contains a
very basic function which includes reservation ,to check pnr status, to print
tickets. In this mini project, there is no login feature. This means he/she can use
all those available features easily without any restriction.

In this system, he/she can view all reserve tickets easily. While reserving tickets,
the user has to enter the number of tickets and his/her name, age. The system
asks for a certain number of inputs depending upon the number of tickets
entered by the user. In this Reservation System, the user can check for pnr
status. This simple console based Reservation system provides one of the simplest
reservation of ticket. There is a database connection in this mini project to save
user’s data permanently and retrieve it.

Modules
The project contains of the following modules:-

1. Train details: This module is used to add train records.

2. Ticket Reservation: This module is used to add ticket details of customer and
also show number of seats occupied in each seat category of a particular train
record.(maximum tickets for each class is restricted to 100 and done using SQL
check constraint)

3. Ticket Cancellation: This module is used to cancel the ticket of given pnr no.

4. Ticket Print: This module is used to print the ticket.

5. Display PNR No status This module shows the pnr no status.


Technologies Used:

SOFTWARE SPECIFICATION:-
Operating System : Windows 7-10

Platform : Python IDLE 3.7,3.8

Database : MySQL

Languages : Python

HARDWARE SPECIFICATION:-

Processor : Dual Core and above

Hard Disk : 50GB

Ram : 1024 MB

Note: For Python-MySQL connectivity, following data have been used:-

Host- localhost, user- root, password- 123, database- rail1


Database tables used
-----Railway Reservation System(Code)-----

import mysql.connector

mydb=mysql.connector.connect(host="localhost",user="root",passwd="123",data
base="rail1")

mycursor=mydb.cursor()

pnr=0

def railresmenu():

while(True):

print("Railway Reservation System")

print("1.Train Detail")

print("2.Reservation of Ticket")

print("3.Cancellation of Ticket")

print("4.Display PNR status")

print("5.Display Ticket")

print("6.Quit")

n=int(input("enter your choice"))

if(n==1):

traindetail()

elif(n==2):

reservation()

elif(n==3):
cancel()

elif(n==4):

displayPNR()

elif(n==5):

printticket()

elif(n==6):

break

else:

print("wrong choice")

def traindetail():

print("Train Details")

ch='y'

while (ch=='y'):

l=[]

tname=input("enter train name :")

l.append(tname)

tnum=int(input("enter train number :"))

l.append(tnum)

src=input("enter train source :")

l.append(src)

des=input("enter train destination :")


l.append(des)

ac1=int(input("enter number of AC 1 class seats"))

l.append(ac1)

ac2=int(input("enter number of AC 2 class seats"))

l.append(ac2)

ac3=int(input("enter number of AC 3 class seats"))

l.append(ac3)

slp=int(input("enter number of sleeper class seats"))

l.append(slp)

train=(l)

sql="insert into traindetail


(tname,tnum,src,des,ac1,ac2,ac3,slp)values(%s,%s,%s,%s,%s,%s,%s,%s)"

mycursor.execute(sql,train)

mydb.commit()

print("\nTrain details added successfully\n")

print("Do you want to insert more train Detail")

ch=input("enter y/n")

def reservation():

print("train details")

sql1="select * from traindetail"

mycursor.execute(sql1)
res=mycursor.fetchall()

for x in res:

print (x)

global pnr

l1=[]

k=[]

pname=input("enter passenger name=")

l1.append(pname)

age=input("enter age of passenger =")

l1.append(age)

trainno=input("enter train number")

l1.append(trainno)

noofpas=int(input("Enter number of passanger:"))

l1.append(noofpas)

print("select a class you would like to travel in")

print("1.AC FIRST CLASS")

print("2.AC SECOND CLASS")

print("3.AC THIRD CLASS")

print("4.SLEEPER CLASS")

cp=int(input("Enter your choice:"))

if(cp==1):

tn=(trainno,)
def retac1(tn):

sql3="select ac1 from traindetail where tnum=%s"

mycursor.execute(sql3,tn)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

x=retac1(tn)

np=x+noofpas

k.append(np)

k.append(trainno)

sql2="update traindetail set ac1 = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)

amount=noofpas*1000

cls='ac1'

elif(cp==2):

tn=(trainno,)

def retac2(tn):

sql3="select ac2 from traindetail where tnum=%s"

mycursor.execute(sql3,tn)

rs=mycursor.fetchall()
for x in rs:

return (x[0])

x=retac2(tn)

np=x+noofpas

k.append(np)

k.append(trainno)

sql2="update traindetail set ac2 = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)

amount=noofpas*800

cls='ac2'

elif(cp==3):

tn=(trainno,)

def retac3(tn):

sql3="select ac3 from traindetail where tnum=%s"

mycursor.execute(sql3,tn)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

x=retac3(tn)

np=x+noofpas

k.append(np)
k.append(trainno)

sql2="update traindetail set ac3 = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)

amount=noofpas*500

cls='ac3'

else:

tn=(trainno,)

def retac4(tn):

sql3="select slp from traindetail where tnum=%s"

mycursor.execute(sql3,tn)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

x=retac4(tn)

np=x+noofpas

k.append(np)

k.append(trainno)

sql2="update traindetail set slp = %s where tnum=%s"

kk=(k)
mycursor.execute(sql2,kk)

amount=noofpas*350

cls='slp'

l1.append(cls)

print("Total amount to be paid:",amount)

l1.append(amount)

pnr=pnr+1

print("PNR Number:",pnr)

print("status: confirmed")

status='confirmed'

l1.append(status)

l1.append(pnr)

train1=(l1)

sql="insert into
passengers(pname,age,trainno,noofpas,cls,amt,status,pnrno)values(%s,%s,%s,%s,
%s,%s,%s,%s)"

mycursor.execute(sql,train1)

mydb.commit()

print("\nReservation completed")

def cancel():

print("Ticket cancel window")

pnr=input("enter PNR for cancellation of Ticket")

pn=(pnr,)
k=[]

def retac4(pn):

sql3="select noofpas,cls,trainno from passengers where pnrno=%s"

mycursor.execute(sql3,pn)

rs=mycursor.fetchall()

for x in rs:

return (x)

x,y,z=retac4(pn)

if y=="ac1":

def retac5():

sql3="select ac1 from traindetail"

mycursor.execute(sql3)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

qqq=retac5()-x

k.append(qqq)

k.append(z)

sql2="update traindetail set ac1 = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)
elif y=="ac2":

def retac6():

sql3="select ac2 from traindetail"

mycursor.execute(sql3)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

qqq=retac6()-x

k.append(qqq)

k.append(z)

sql2="update traindetail set ac2 = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)

elif y=="ac3":

def retac7():

sql3="select ac3 from traindetail"

mycursor.execute(sql3)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

qqq=retac7()-x

k.append(qqq)
k.append(z)

sql2="update traindetail set ac3 = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)

elif y=="slp":

def retac8():

sql3="select slp from traindetail"

mycursor.execute(sql3)

rs=mycursor.fetchall()

for x in rs:

return (x[0])

qqq=retac8()-x

k.append(qqq)

k.append(z)

sql2="update traindetail set slp = %s where tnum=%s"

kk=(k)

mycursor.execute(sql2,kk)

sql="delete from passengers where pnrno=%s"

mycursor.execute(sql,pn)

mydb.commit()

print("\nTicket cancelled")

print("\nGo back to menu")


def printticket():

pnr=input("enter PNR no for Ticket")

pn=(pnr,)

sql="select tname,tnum,pname,age,status from traindetail,passengers where


tnum=trainno and pnrno=%s"

mycursor.execute(sql,pn)

rs=mycursor.fetchall()

print("\nTicket details\n")

for x in rs:

print ("Train name :",x[0])

print ("Train Number :",x[1])

print ("Passenger Name :",x[2])

print ("Passenger Age :",x[3])

print ("Ticket Stauts :",x[4])

print("\n")

def displayPNR():

print("\nPNR STATUS window\n")

pnr=input("enter PNR NUMBER")

pn=(pnr,)

sql="select * from passengers where pnrno=%s"

mycursor.execute(sql,pn)
res=mycursor.fetchall()

print("PNR STATUS are as follows : ")

print("(passenger name,age,trainno, noofpas,class,amount,status, pnrno)")

for x in res:

print(x)

print("Go back to menu")

railresmenu()
BIBLIOGRAPHY:

• Sumita Arora Python Class XII


• Preeti Arora Python Class XII
• www.w3school.com

You might also like