The Baptist Convent Senior Secondary School: Project File
The Baptist Convent Senior Secondary School: Project File
SECONDARY SCHOOL
Computer Science
[Python]
PROJECT FILE
Railway Reservation System
Bhavya Kawatra
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.
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:
Advantages of 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.
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:-
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.
SOFTWARE SPECIFICATION:-
Operating System : Windows 7-10
Database : MySQL
Languages : Python
HARDWARE SPECIFICATION:-
Ram : 1024 MB
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("1.Train Detail")
print("2.Reservation of Ticket")
print("3.Cancellation of Ticket")
print("5.Display Ticket")
print("6.Quit")
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=[]
l.append(tname)
l.append(tnum)
l.append(src)
l.append(ac1)
l.append(ac2)
l.append(ac3)
l.append(slp)
train=(l)
mycursor.execute(sql,train)
mydb.commit()
ch=input("enter y/n")
def reservation():
print("train details")
mycursor.execute(sql1)
res=mycursor.fetchall()
for x in res:
print (x)
global pnr
l1=[]
k=[]
l1.append(pname)
l1.append(age)
l1.append(trainno)
l1.append(noofpas)
print("4.SLEEPER CLASS")
if(cp==1):
tn=(trainno,)
def retac1(tn):
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)
kk=(k)
mycursor.execute(sql2,kk)
amount=noofpas*1000
cls='ac1'
elif(cp==2):
tn=(trainno,)
def retac2(tn):
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)
kk=(k)
mycursor.execute(sql2,kk)
amount=noofpas*800
cls='ac2'
elif(cp==3):
tn=(trainno,)
def retac3(tn):
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)
kk=(k)
mycursor.execute(sql2,kk)
amount=noofpas*500
cls='ac3'
else:
tn=(trainno,)
def retac4(tn):
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)
kk=(k)
mycursor.execute(sql2,kk)
amount=noofpas*350
cls='slp'
l1.append(cls)
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():
pn=(pnr,)
k=[]
def retac4(pn):
mycursor.execute(sql3,pn)
rs=mycursor.fetchall()
for x in rs:
return (x)
x,y,z=retac4(pn)
if y=="ac1":
def retac5():
mycursor.execute(sql3)
rs=mycursor.fetchall()
for x in rs:
return (x[0])
qqq=retac5()-x
k.append(qqq)
k.append(z)
kk=(k)
mycursor.execute(sql2,kk)
elif y=="ac2":
def retac6():
mycursor.execute(sql3)
rs=mycursor.fetchall()
for x in rs:
return (x[0])
qqq=retac6()-x
k.append(qqq)
k.append(z)
kk=(k)
mycursor.execute(sql2,kk)
elif y=="ac3":
def retac7():
mycursor.execute(sql3)
rs=mycursor.fetchall()
for x in rs:
return (x[0])
qqq=retac7()-x
k.append(qqq)
k.append(z)
kk=(k)
mycursor.execute(sql2,kk)
elif y=="slp":
def retac8():
mycursor.execute(sql3)
rs=mycursor.fetchall()
for x in rs:
return (x[0])
qqq=retac8()-x
k.append(qqq)
k.append(z)
kk=(k)
mycursor.execute(sql2,kk)
mycursor.execute(sql,pn)
mydb.commit()
print("\nTicket cancelled")
pn=(pnr,)
mycursor.execute(sql,pn)
rs=mycursor.fetchall()
print("\nTicket details\n")
for x in rs:
print("\n")
def displayPNR():
pn=(pnr,)
mycursor.execute(sql,pn)
res=mycursor.fetchall()
for x in res:
print(x)
railresmenu()
BIBLIOGRAPHY: