Passengers Project

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

import mysql.

connector as x

from tabulate import tabulate

con=x.connect(host='localhost',user='root',passwd='root',database='railwaymanagement')

cur=con.cursor()

def Addnewrecord():

PN=(input('Enter the Passenger Name : '))

PA=input('Enter Passenger Age : ')

G=input('Enter the Gender of Passengers : ')

T=input('Enter the Name of Train : ')

TN=input('Enter the Train Number : ')

DE=input('Enter the place of Departure : ')

A=input('Enter the place of Arrival: ')

DATE=input('Enter Date of Travel:' )

DAY=input('Enter the Day of Travel:' )

TD=input('Enter the Time of Departure:' )

Tn=int(input('Enter the Ticket Number:'))

cur.execute('insert into passengers


values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',(PN,PA,G,T,TN,DE,A,DATE,DAY,TD,Tn))

ch=input('Do you want to Save this Record?(Y,N) : ')

if ch in 'Y,y':

con.commit()

print('Record Has Been Added Successfully.')

else:

print('Record Addition Terminated.')

def DisplayAll():

cur.execute('select * from passengers')

data=cur.fetchall()

print(tabulate(data,headers=['PassengerName','PassengerAge','PassengerGender','TrainName','TrainNo','
DepartureFrom','ArrivalTo','Date','Day','TimeOfDeparture','TicketNo'],tablefmt='grid'))
def Search():

Tn=int(input('Enter the Ticket Number to be Searched : '))

cur.execute('select * from passengers where TicketNo=%s',(Tn,))

data=cur.fetchall()

if data==None:

print('Ticket Number Not Found.')

else:

print(tabulate(data,headers=['PassengerName','PassengerAge','PassengerGender','TrainName','TrainNo','
DepartureFrom','ArrivalTo','Date','Day','TimeOfDeparture','TicketNo'],tablefmt='grid'))

def Delete():

Tn=int(input('Enter the Ticket Number to be Deleted : '))

cur.execute('select * from passengers where TicketNo=%s',(Tn,))

data=cur.fetchall()

if data==None:

print('Ticket Number Not Found.')

else:

print(tabulate(data,headers=['PassengerName','PassengerAge','PassengerGender','TrainName','TrainNo','
DepartureFrom','ArrivalTo','Date','Day','TimeOfDeparture','TicketNo'],tablefmt='grid'))

ch=input('Do you want to Delete this Record?(Y,N) : ')

if ch in 'Y,y':

cur.execute('delete from passengers where TicketNo=%s',(Tn,))

con.commit()

else:

print('Record Deletion Terminated.')

def Modify():

n=int(input('Enter the Ticket Number to be Modified : '))

cur.execute('select * from passengers where TicketNo=%s',(Tn,))

data=cur.fetchall()
if data==None:

print('Ticket Number Not Found.')

else:

print(tabulate(data,headers=['PassengerName','PassengerAge','PassengerGender','TrainName','TrainNo','
DepartureFrom','ArrivalTo','Date','Day','TimeOfDeparture','TicketNo'],tablefmt='grid'))

ch=input('Do you want to Modify this Record?(Y,N) : ')

if ch in 'Y,y':

PassengerName=input('Enter the Passenger Name(Press Enter to Skip) : ')

if PassengerName!='':

cur.execute('update passengers set PassengerName=%s where TicketNo=%s',(PN,Tn,))

con.commit()

PassengerAge=input('Enter the age of Passenger(Press Enter to Skip) :')

if PassengerAge!='':

cur.execute('update passengers set PassengerAge=%s where TicketNo=%s',(PA,Tn,))

con.commit()

PassengerGender=input('Enter the Gender of Passenger(Press Enter to Skip) : ')

if PassengerGender!='':

cur.execute('update passengers set PassengerGender=%s where TrainNo=%s',(G,Tn,))

con.commit()

TrainName=input('Enter the place of Arrival(Press Enter to Skip) : ')

if TrainName!='':

cur.execute('update passengers set TrainName=%s where TicketNo=%s',(T,Tn,))

con.commit()

TrainName=input('Enter the place of Arrival(Press Enter to Skip) : ')

if TrainNo!='':

cur.execute('update passengers set TrainNo=%s where TicketNo=%s',(T,Tn,))

con.commit()

DepartureFrom=input('Enter the place of Departure(Press Enter to Skip) : ')


if DepartureFrom!='':

cur.execute('update passengers set DepartureFrom=%s where TicketNo=%s',(DE,Tn,))

con.commit()

ArrivalTo=input('Enter the place of Arrival(Press Enter to Skip) : ')

if ArrivalTo!='':

cur.execute('update passengers set ArrivalTo=%s where TicketNo=%s',(A,Tn,))

con.commit()

Date=input('Enter the Date of Travel(Press Enter to Skip) : ')

if Date!='':

cur.execute('update passengers set Date=%s where TicketNo=%s',(DATE,Tn,))

con.commit()

Day=input('Enter the Day of Travel(Press Enter to Skip) : ')

if Day!='':

cur.execute('update passengers set Day=%s where TicketNo=%s',(DAY,Tn,))

con.commit()

TimeOfDeparture=input('Enter the Time of Departure(Press Enter to Skip) : ')

if TimeOfDeparture!='':

cur.execute('update passengers set Day=%s where TicketNo=%s',(TD,Tn,))

con.commit()

else:

print('Record Modification Terminated.')

while True:

print("1.ADD a new Passenger.")

print("2.DISPLAY the Details of Passengers.")

print("3.SEARCH the Details of any Passenger.")

print("4.DELETE the Details of any Passenger.")

print("5.CHANGE the Details of any Passenger.")

print("6.EXIT.")

ch=int(input('Enter Your Choice : '))


if ch==1:

Addnewrecord()

elif ch==2:

DisplayAll()

elif ch==3:

Search()

elif ch==4:

Delete()

elif ch==5:

Modify()

elif ch==6:

break

You might also like