Train Ticket Reservation Programl
Train Ticket Reservation Programl
connector as puvi
mcon=puvi.connect(host='localhost',user='root',passwd='Research@#16',database='puvi')
cur=mcon.cursor()
def gap():
print('''
''')
def g():
print()
def fetch():
f=cur.fetchall()
for d in f:
print(d)
def l():
for j in range(95):
print('_',end='_')
print()
def s():
for i in range(45):
print(' ',end=' ')
def error():
s()
for i in range(13):
print('-',end='')
g()
s()
print('| ! ERROR ! |')
s()
for i in range(13):
print('-',end='')
def ticket():
print('THE TRAIN TICKET FOR ONE WAY TO "',stpng,'" WILL BE GENERATED SOON.')
l()
gap()
for i in range(45):
print(' ',end=' ')
print('TRAIN TICKET')
gap()
g()
print('Train no. : ',f[0],' '*20,'Train name : ',f[1],' '*(45-len(f[1])),'Source station : ',f[2],' '*(40-len(f[2])),'Final station : ',f[3])
gap()
print('Destination : ',stpng,' '*(45-len(stpng)),'Class : ',pclass,' '*(20-len(pclass)),'Date : ',date,' '*30,'Time : ',f[4])
gap()
print('Name:',pname,' '*(40-len(pname)),'Age : ',pAge,' '*(30-len(pAge)),'Gender : ',pgender,' '*30,'Concession : ',con)
gap()
print('Total Fare : Rs.',fprice,'/- only')
gap()
l()
def date1():
g()
print('The day(s) and time your train is available are as follows in the format (DAY(S) , HH:MM:SS) : ')
g()
cur.execute(sdd.format(fs))
fetch()
def dtpr():
g()
chk2=True
while chk2==True:
g()
day=input('Enter the day of your travel(the first letter must be uppercase and remaining must be lowercase) : ')
for i in kt:
if fs in i:
for j in dt:
if i[3] in j:
x=j[1]
avail=x.split(',')
if day not in avail:
error()
print('Error!!! Enter a date on which the train is available!!!')
chk2=True
else:
chk2=False
for i in range(0,40):
print('-',end='-')
print('WELCOME TO INDIAN RAILWAYS!!!',end='-')
for i in range(0,40):
print('-',end='-')
gap()
for i in range(0,18):
print(' ',end=' ')
print(' WE ASSURE YOU A SAFE AND HAPPY JOURNEY :)')
gap()
chk=True
while chk==True:
fs=input('Enter the city code of the train you want to travel : ')
for i in dfc:
if fs in i:
K=False
break
if K!=False:
error()
print('ERROR!!! ENTER A VALID CITY CODE!!!')
chk=True
else:
chk=False
g()
print('THE STOPPINGS AT WHICH THE TRAIN STOPS ARE : ',end=' ')
g
()
sl1=len(si[fs])
for i in si[fs]:
if i==c:
continue
else:
print(i,end=',')
sdd='select days,boarding_time from days_available d,Train_FROM_CHENNAI fc where d.d_code=fc.d_code and city_code="{}"'
date1()
cfrm=input('If you agree with the above days and timing enter "CONTINUE" : ')
if cfrm=='CONTINUE'or cfrm=='continue':
stpng=input('Enter the name of the station you want to reach: ')
pname=input('Enter passenger name : ')
pAge=input('Enter passenger age in number : ')
pgender=input('Enter passenger gender : ')
pclass=input('Enter the desired class for travelling as per the valid abbreviation: ')
g()
chk1=int(input('Is this passenger eligible for concession? [Enter 0 for "NO" and 1 for "YES"] '))
if chk1==1:
g()
conc=input('Enter the concession code the passenger can avail : ')
conn=ct[conc][1]
con=ct[conc][0]
else:
con='NONE'
conn=0
ptfc='select price_code from Train_from_chennai where city_code="{}"'
kt=dfc
g()
date=input('Enter the date you want to travel (in the format "DD-MM-YYYY") : ')
dtpr()
cur.execute(ptfc.format(fs))
pcode=cur.fetchone()
ind=pl.index(pclass)
for i in ft :
if pcode[0] in i:
j=i
break
else:
continue
pr1=j[ind]
pr2=(si[fs][stpng][0]/50)*int(pr1)
disc=(pr2*conn)/100
fprice=pr2-disc
sst=c
tdfc='select train_no,train_name,source_station,final_station,boarding_time from Train_from_chennai where city_code="{}"'
cur.execute(tdfc.format(fs))
f=cur.fetchone()
print(f)
ticket()
gap()
cfrm1=int(input('ENTER(1 if "YES" and 0 if "NO") WHETHER YOU ALSO WANT TO BOOK A RETURN TICKET : '))
if cfrm1==1:
print('ENTER THE FOLLOWING DETAILS FOR BOOKING A RETURN TICKET: ')
sdd='select days,boarding_time from days_available d,Train_TO_CHENNAI fc where d.d_code=fc.d_code and city_code="{}"'
date1()
kt=dtc
pclass=input('Enter the desired class for travelling as per the valid abbreviation: ')
ptfc='select price_code from Train_to_chennai where city_code="{}"'
date=input('Enter the date you want to travel (in the format "DD-MM-YYYY") : ')
dtpr()
cur.execute(ptfc.format(fs))
pcode=cur.fetchone()
ind=pl.index(pclass)
for i in ft :
if pcode[0] in i:
j=i
break
else:
continue
pr1=j[ind]
pr2=(si[fs][stpng][0]/50)*int(pr1)
disc=(pr2*conn)/100
fprice=pr2-disc
sst=stpng
cur.execute('select train_no,train_name,source_station,final_station,boarding_time from Train_to_chennai where city_code="{}"'.format(fs))
f=cur.fetchone()
ticket()