Railway Reservation Cs
Railway Reservation Cs
Durgapur
Affiliated to the Central Board Of Secondary
Education,Delhi
Website:https://crpfdurgapur.kvs.ac.in
2020-2021
DEPARTMENT OF COMPUTER SCIENCE
TOPIC – RAILWAY RESERVATION
Signature of Principal
COMPUTER
SCIENCE
PROJECT
ON
RAILWAY
RESERVATION
DONE BY:-
ANUPAM SINGHA
ABHINAV VERMA
TABLE OF CONTENT
SL. TOPIC PG NO
NO.
1. Introduction
01
2. Function
Description 02-04
3. Tables
Used 05-06
4. Source Code
(Program Listing) 07-12
5. Output
13-16
6. Conclusion 17
INTRODUCTION
This project introduces railway reservation. This
system will help to list ,add , query about railway
reservation . This is very useful in keeping the
records of railway queris. The step by step
procedure is explained in this project. This project
is developed in Python language.Proper comments
have been given at desired locations to make the
project user friendly. Various funtions are used to
make a complete use of this language. Thus this
project is well versed with the program railway
reservation which teaches basic railway system .
Function Description
Function name- railresmenu()
Parameters-Nil
Task- choice for reservation
Variables Description:-
Variables Description
n Choice varable
Function Name-traindetail()
Parameters-Nil
Task- train query
Variables Description:-
Variables Description
n Option choice
Ch Chosing yes or no
l Empty list for variable
name Train name for search
tnum Train number
Ac1 Number of AC1 class seats
Ac2 Number of AC2 class seats
Ac3 Number of AC3 class seats
SIP Number of sleeper class seats
train Train details
sql Inserting data in database
Function Name-reservation()
Parameters-Nil
Task-making reservation for different classes
Variables Description:-
Variables Description
Pnr Pnr number
L1 Empty list
Pname Passenger name
Age Age of passenger
Trainno Train number
Np Number of passenger
Cp Choice to get bill
Amount Calculating amount per passenger
Function Name-cancel()
Parameters-Nil
Task-for cancellation of reservation
Variables Description:-
Variables Description
epnr Pnr of cancellation ticket
Pn Reference to variable pnr
sql Updating status to delete in database
Function Name-displayPNR()
Parameters-Nil
Task- for query and changes about PNR
Variables Description:-
05
Variables Description
Pnr Entering pnr number
Pn Reference variable pnr
Sql To select the pnr nmber
TABLES
USED
PROGRM
LISTING
Python Code:
import mysql.connector
import os
import platform
#import pandas as pd
pnr=1024
mydb=mysql.connector.connect(host="localhost",user="root",passwd="scottiger",database="rail");
mycursor=mydb.cursor()
def railresmenu():
print("Railway Reservation ")
print("1.Train Detail")
print("2.Reservation of Ticket")
print("3.Cancellation of Ticket")
print("4.Display PNR status")
print("5.Quit")
#print(" ",end="\n"*50)
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):
exit(0)
else:
print("wrong choice")
def traindetail():
print("Train Details")
ch='y'
while (ch=='y'):
l=[]
name=input("enter train name :")
l.append(name)
tnum=int(input("enter train number :"))
l.append(tnum)
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,ac1,ac2,ac3,slp)values(%s,%s,%s,%s,%s,
%s)"
mycursor.execute(sql,train)
mydb.commit()
print("insertion completed")
print("Do you want to insert more train Detail")
ch=input("enter yes/no")
print('\n' *10)
print("===================================================================")
railresmenu()
def reservation():
global pnr
l1=[]
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)
np=int(input("Enter number of passanger:"))
l1.append(np)
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):
amount=np*1000
cls='ac1'
elif(cp==2):
amount=np*800
cls='ac2'
elif(cp==3):
amount=np*500
cls='ac3'
else:
amount=np*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")
sts='conf'
l1.append(sts)
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("insertion completed")
print("Go back to menu")
print('\n' *10)
print("===================================================================")
railresmenu()
railresmenu()
def cancel():
print("Ticket cancel window")
pnr=input("enter PNR for cancellation of Ticket")
pn=(pnr,)
sql="update passengers set status='deleted' where pnrno=%s"
mycursor.execute(sql,pn)
mydb.commit()
print("Deletion completed")
print("Go back to menu")
print('\n' *10)
print("===================================================================")
railresmenu()
railresmenu()
def displayPNR():
print("PNR STATUS window")
pnr=input("enter PNR NUMBER")
pn=(pnr,)
sql="select * from passengers where pnrno=%s"
mycursor.execute(sql,pn)
res=mycursor.fetchall()
#mydb.commit()
print("PNR STATUS are as follows : ")
print("(pname,age,trainno, noofpas,cls,amt,status, pnrno)")
for x in res:
print(x)
#print("Deletion completed")
print("Go back to menu")
print('\n' *10)
print("===================================================================")
railresmenu()
railresmenu()
OUTPUT
>>> railresmenu()
Railway Reservation
1.Train Detail
2.Reservation of Ticket
3.Cancellation of Ticket
4.Display PNR status
5.Quit
enter your choice1
Train Details
enter train name :madurai chainnai
enter train number :22206
enter number of AC 1 class seats200
enter number of AC 2 class seats200
enter number of AC 3 class seats200
enter number of sleeper class seats4000
insertion completed
Do you want to insert more train Detail N
SCREEN 2
Railway Reservation
1.Train Detail
2.Reservation of Ticket
3.Cancellation of Ticket
4.Display PNR status
5.Quit
enter your choice2
enter passenger name=JOHN
enter age of passenger =23
enter train number22206
Enter number of passanger:2
select a class you would like to travel in
1.AC FIRST CLASS
2.AC SECOND CLASS
3.AC THIRD CLASS
4.SLEEPER CLASS
Enter your choice:2
Total amount to be paid: 1600
PNR Number: 1025
status: confirmed
SCREEN 3
===================================================================
Railway Reservation
1.Train Detail
2.Reservation of Ticket
3.Cancellation of Ticket
4.Display PNR status
5.Quit
enter your choice 3
Ticket cancel window
enter PNR for cancellation of Ticket1025
Deletion completed
Go back to menu
SCREEN:4
===================================================================
Railway Reservation
1.Train Detail
2.Reservation of Ticket
3.Cancellation of Ticket
4.Display PNR status
5.Quit
enter your choice4
PNR STATUS window
enter PNR NUMBER1025
PNR STATUS are as follows :
(pname,age,trainno, noofpas,cls,amt,status, pnrno)
('JOHN', 23, 22206, 2, 'ac2', 1600, 'deleted', 1025)
Go back to menu
CONCLUSION
So railway reservation is an easy program which helps
to teach about registeration,pnr,queries and much more.
It helps students to learn all types of concept about
database , connectivity and function.