0% found this document useful (0 votes)
16 views185 pages

Railway Management Final11

Uploaded by

sunnykumar67ew
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 (0 votes)
16 views185 pages

Railway Management Final11

Uploaded by

sunnykumar67ew
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/ 185

DAVPUBLICSCHOOLKEDLA

RAMGARH, JHARKHAND
SESSION:-2024-2025
SCIENCE

COMPUTER SCIENCE IN PYHON PROGRAM


RAILWAY TICKETING SYSTEM

Submitted by :Varsha Kumari


Admission no. :
Roll no. :
Class :XII
Guidedby : Mr.Deepak Sinha

Signature of the teacher Remarks


INDEX

Serial number Topic Pagenumber


1. Undertaking 3
2. Certificate 4
3. Acknowledgement
5
4. Content
Introduction to the
6
5.
project 7
6. System reqirements of 8
the projects
7. Coding 9-110
8. Screenshots of outputs 111-178
9. Screenshots of MySQL 178-181
10. References
182
UNDERTAKING

We declare that the work presented in this project titled

RAILWAY TICKETING SYSTEM,submitted to Mr.DeepakSinha

PGT:Computer Science in Python programme,


DAV PUBLIC SCHOOL KEDLA RAMGARH, JHARKHAND

For the award of the C BSE ISSCE classXII certificate

have not plagiarized or submitted the same work for the

award of any other examination. In case this undertaking is

found incorrect, we accept that our Certificates may be

unconditionally withdrawn.

3|Page
CERTIFICATE

Certified that the work contained in the project titled


RAILWAY TICKETING SYSTEM,byVARSHA KUMARI,has
Been carried out under my supervision and that this work has
not been submitted else where for a AISSE certificate.

ProjectGuide:

DEEPAK SINHA
PGT-Computer Science
in Python Program
DAV PublicSchool
Kedla ,Ramgarh
JHARKHAND

4|Page
Acknowledgements

I would like to express my special thanks of


gratitude to my teacher Mr. Deepak Sinha

who gave me the golden opportunity to do this


wonderful project onthe topic Railway Ticketing
System , which also helped me in doing a lot of
Research and I came to know about so many new
things I am really thankful to them.
Secondly I would also like to thank my
parentsand friends who helped me a lot in
finalizing this project within the limited time
frame.

5|Page
Contents

1. Introduction of the Project.


2. System Requirements of the
Project.
3. PythonCoding.

4. Output of the Project.

5. Screenshots of MySQL

6. References.

6|Page
Introduction of the Project

This project is similar to an Indian Railway


app. It allows the user to book, cancel,
modify or view , their respective bookings.
It allows the admin to change the train’s
records and their records. In this project
there is also an option, for registering the
user in Indian railway.
SYSTEM
REQIREMENTS OF
PROJECTS :

1. Windows
operating system
2. Python IDLE
3.MySQL
4.MySQL connector
CODING:
import connectorfunction as a

import connfunatt as c

print('Type 1for running the application')

print('Type2fordatabaserelatedqueries')

choice=input('1-2 : ')

if choice == '1' :

a.welcometoindianrailways()

elif choice =='2' :

c.databaserelatedqueries()

else:

exit()
MODULE1:connector function

Import mysql.connector as myc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

import gtts

from playsound import

playsoundimport os

importre

defuserid():

m=input('User id(6 digits ),numeric : ')

ln=len(m)

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if

(regex.search(m) != None ):

print("Specialcharactersarenotallowed")

m=userid()

else:

if(m.isalpha()):
print('Only numerals are allowed' ,'\U0001F610')

m=userid()

elif(m.isnumeric()):

ifln!=6:

print('Userid shouldbeof6numerals','\U0001F610') m=userid()

elif(notm.isdigit()andnotm.isalpha()):

print('Onlynumeralsareallowed','\U0001F610')

m=userid()

returnmdef a()

m=input('User id(6 digits ),numeric

:')import mysql.connector as myc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

qr='select*fromuser_infowhereuser_id=%s'va=(m,)

d.execute(qr,va)

f=d.fetchall()

rw=d.rowcount
regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(m)

!= None ):

print("Specialcharactersarenotallowed")

m=a()

else:

ifrw ==1:

print('Useridexist,pleaseselectanotheruserid','
\U0001F610')

m=a()else

ln=len(m)

if(m.isalpha()):

print('Onlynumeralsareallowed','\U0001F610')

m=a()

elif(m.isnumeric()):

ifln!=6:

print('Useridshouldbeof6numerals','
\U0001F610')

m=a()

elif(notm.isdigit()andnotm.isalpha()):

print('Onlyalphabetsareallowed','\U0001F610')
m=a()

else :

print('Onlynumeralsareallowed','\U0001F610')

m=a()

returnmdef

username():

n=input('User name(Use undersore(_) instead of space ) : ')

regex=re.compile('[-

@!#$%^&*()<,.+>?/\|}{1234567890~:]')if(regex.search(n) ==

None ):

print("Accepted ")

else :

if(n.isdigit()):

print('Onlyalphabetsare allowed',' \U0001F610') n=username()

elif(notn.isdigit()andnotn.isalpha()):

print('Onlyalphabetsare allowed',' \U0001F610') n=username()

return n def

nusername() :

n=input('User name(Use undersore(_) instead of space ) : ')

regex=re.compile('[-@!#$%^&*()<,.+>?/\|}{1234567890~:]')
if(regex.search(n)==None):

print("Accepted ")

else:

if(n.isdigit()):

print('Onlyalphabetsare allowed',' \U0001F610') n=username()

elif(notn.isdigit()andnotn.isalpha()):

print('Onlyalphabetsare allowed',' \U0001F610') n=username()

returnn

defc():

o=input('Userage:') ln=len(o)

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(o)

!= None ):

print("Specialcharactersarenotallowed")

o=c()

else:

if(o.isalpha()):

print('Onlynumeralsareallowed','\U0001F610') o=c()
elif(o.isnumeri

c()):op=int(o)

if(op > 116) :

print('Invalidage','\U0001F610') o=c()

elif (not o.isnumeric()andnoto.isalpha()):

print('Onlyalphabetsareallowed','\U0001F610') o=c()

else:

print('Onlynumeralsareallowed','\U0001F610') o=c()

returno

defnc():

o=input('Enternewuserage:')

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(o)

!= None ):

print("Specialcharactersarenotallowed")

o=nc()

else:

ln=len(o)

if(o.isalpha()):
print('Onlynumeralsareallowed','\U0001F610') o=nc()

elif(o.isnumeri

c()):op=int(o)

if(op > 116) :

print('Invalidage','\U0001F610') o=nc()

elif (not o.isnumeric()andnoto.isalpha()):

print('Onlyalphabetsareallowed','\U0001F610')

o=nc()

else:

print('Onlynumeralsareallowed','\U0001F610') o=nc()

returno

defda():

p=input('Usergender:')

ln=len(p)

ph=['m','f']

pk=p.lower()

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(p)

!= None ):
print("Specialcharactersarenotallowed")

p=da()

else:

if(p.isnumeric()):

print('Onlyalphabetsareallowed','\U0001F610') p=da()

elif

(p.isalpha())

:ifln!=1:

print('Gendershouldbeof1characters(morf)','
\U0001F610')

p=da()

elif pk != ph[0] and pk != ph[1] :

print('Onlymandfareallowed') p=da()

elif (not p.isnumeric() andnotp.isalpha()):

print('Onlyalphabetsareallowed','\U0001F610')

p=da()

returnp

defe():

q=input('Usermobileno(10digits),numeric:')

ln=len(q)
regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(q)

!= None ):

print("Specialcharactersarenotallowed")

q=e()

else:

if(q.isalpha()):

print('Onlynumeralsareallowed','\U0001F610') q=e()

elif(q.isnumeric()):

ifln!=10:

print('Mobilenumbershouldbeof10numerals',
'\U0001F610')

q=e()

elif(notq.isnumeric()andnotq.isalpha()):

print(' Only numerals areallowed ',' \U0001F610') q=e()

returnqdefne()

q=input('Enternewmobilenumber(10digits),numeric:')

ln=len(q)

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')
if(regex.search(q)!=None):

print("Specialcharactersarenotallowed")

q=ne()

else:

if(q.isalpha()):

print('Onlynumeralsareallowed','\U0001F610') q=ne()

elif(q.isnumeric()):

ifln!=10:

print('Mobilenumbershouldbeof10numerals',
'\U0001F610')

q=ne()

elif(notq.isdigit()andnotq.isalpha()):

print('Onlynumeralsare allowed','\U0001F610') q=ne()

returnq

deffa():

r=input('Password(4digits),numeric:')

ln=len(r)

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')
if(regex.search(r)!=None):

print("Specialcharactersarenotallowed")

r=fa()

else:

if(r.isalpha()):

print('Onlynumeralsareallowed','\U0001F610') r=fa()

elif

(r.isnumeric())

:ifln!=4:

print('Passwordshouldbeof4numerals','
\U0001F610')

r=fa()

else:

print('Onlynumeralsareallowed','\U0001F610') r=fa()

returnr

defnfa():

r=input('Enternewpassword(4digits),numeric:')

ln=len(r)

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(r)

!= None ):
print("Specialcharactersarenotallowed")

n=nfa()

else:

if(r.isalpha()):

print('Onlynumeralsareallowed','\U0001F610') r=nfa()

elif

(r.isnumeric())

:ifln!=4:

print('Passwordshouldbeof4numerals','
\U0001F610')

r=nfa()

else:

print('Onlynumeralsareallowed','\U0001F610') r=nfa()

returnrdef

trainid() :

r=input('Enter train id(5 digits),numeric : ')

ln=len(r)

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(r)

!= None ):

print("Specialcharactersarenotallowed")
r=trainid()

else :

if(r.isalpha()):

print('Onlynumeralsareallowed','\U0001F610')

r=trainid()

elif

(r.isnumeric())

:ifln!=5:

print('Trainid shouldbe of5 numerals',' \U0001F610')

r=trainid()

else:

print('Onlynumeralsareallowed','\U0001F610')

r=trainid()

returnr

defnewtrainid():

r=input('Trainid(6digits),numeric:')

ln=len(r)

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()
qr='select*fromtrains_infowheretrain_id=%s'va=(r,)

d.execute(qr,va)

f=d.fetchall()

rw=d.rowcount

regex=re.compile('[-

@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(r) !=

None ):

print("Specialcharactersarenotallowed")

r=trainid()

else:

ifrw==1:

print('Train with given id is already registered')

r=newtrainid()

else:

if(r.isalpha()):

print('Onlynumeralsareallowed','\U0001F610')

r=trainid()

elif

(r.isnumeric())

:ifln!=5:

print('Trainid shouldbe of5 numerals',' \U0001F610')

r=trainid()
else:

print('Onlynumeralsareallowed','\U0001F610')

r=trainid()

return r def

trainname():

n=input('Train name(Use undersore(_) instead of space ) : ')

regex=re.compile('[-

@!#$%^&*()<123456789,.+>?/\|}{~:]')if(regex.search(n) ==

None ):

print("Accepted")

else :

if(n.isdigit()):

print('Onlyalphabetsare allowed',' \U0001F610') n=trainname()

elif(notn.isdigit()andnotn.isalpha()):

print('Onlyalphabetsare allowed',' \U0001F610') n=trainname()

returnndef

trsource() :

n=input('Entersource:')

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(n)

!= None ):
print("Specialcharactersarenotallowed")

n=trsource()

else:

if(n.isdigit()):

print('Onlyalphabetsare allowed',' \U0001F610') n=trsource()

elif(notn.isdigit()andnotn.isalpha()):

print('Onlyalphabetsare allowed',' \U0001F610') n=trsource()

return n def

trdestination() :

n=input('Enterdestination:')

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(n)

!= None ):

print("Specialcharactersarenotallowed") n=trdestination()

else:

if(n.isdigit()):

print('Onlyalphabetsareallowed','\U0001F610') n=trdestination()

elif(notn.isdigit()andnotn.isalpha()):
print('Only alphabets are allowed',' \U0001F610')

n=trdestination()

return n def

trinterstations() :

n=input('Enterinterstations(seperatedwithcommas(,):') regex

=re.compile('[-@!#1234567890$%^_&*()<.+>?/\|}{~:]')

if(regex.search(n) != None ):

print("Special characters are not allowed")

n=trinterstations()

else:

if(n.isdigit()):

print('Onlyalphabetsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=trinterstations()elif(

n.isalpha() ) :

print('Onlyalphabetsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=trinterstations()

return n

deftrfare():
n=input('Enterfare(seperatedwithcommas(,):')

regex = re.compile('[-
@!#$%^_&*()<.+>qwertyuioplkjhgfdsazxcvbnm?/\|}{~:]')

if(regex.search(n)!=None):

print("Specialcharactersarenotallowed")

n=trfare()

else:

if(n.isdigit()):

print('Onlynumeralsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=trfare()

elif(n.isalpha()):

print('Onlynumeralsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=tr()

returnn

def ntrainname() :

importre

import mysql.connector as myc

conn=myc.connect(host='localhost',user='root',
passwd='student',database='railway_ticketing_software')
d=conn.cursor()

n=trainname()

qr=('select * from trains_info where train_name=%s')

vl=(n,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw!=1 :

regex= re.compile('[-

@!#$%=^&*()<,.+>?/\|}{~:]')if(regex.search(n)

== None ):

print("Accepted") else

if(n.isdigit()):

print('Onlyalphabetsareallowed(Useundersore(_)insteadofspace) ', '


\U0001F610')

n=ntrainname() if (

n.isdigit()) :

print('Onlyalphabetsareallowed(Useundersore(_)insteadofspace) ', '


\U0001F610')

n=ntrainname()
else:

print('Trainwithsamenamealreadyexistspleaseselectanothername') n=ntrainname() return

defntrsource():

n=input('Enternewsource:')

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(n)

!= None ):

print("Specialcharactersarenotallowed")

n=ntrsource()

else:

if(n.isdigit()):

print('Onlyalphabetsare allowed',' \U0001F610') n=ntrsource()

elif(notn.isdigit()andnotn.isalpha()):

print('Onlyalphabetsare allowed',' \U0001F610') n=ntrsource()

return n def

ntrdestination():
n=input('Enternewdestination:')

regex=re.compile('[-@!#$%^_&*()<,.+>?/\|}{~:]')if(regex.search(n)

!= None ):

print("Specialcharactersarenotallowed")

n=ntrdestination()

else:

if(n.isdigit()):

print('Onlyalphabetsareallowed','\U0001F610') n=ntrdestination()

elif(notn.isdigit()andnotn.isalpha()):

print('Onlyalphabetsareallowed','\U0001F610') n=ntrdestination()

return n def

ntrinterstations() :

n=input('Enternewinterstations(seperatedwithcommas(,):')

regex=re.compile('[-@!#1234567890$%^_&*()<.+>?/\|}{~:]')

if(regex.search(n) != None ):

print("Specialcharactersarenotallowed")

n=ntrinterstations()

else:

if(n.isdigit()):
print('Onlyalphabetsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=ntrinterstations()elif(

n.isalpha() ) :

print('Onlyalphabetsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=ntrinterstations()r

eturn n

defntrfare():

n=input('Enternewfare(seperatedwithcommas(,):')

regex = re.compile('[-
@!#$%^_&*()<.+>qwertyuioplkjhgfdsazxcvbnm?/\|}{~:]')

if(regex.search(n)!=None):

print("Specialcharactersarenotallowed")

n=ntrfare()

else:

if(n.isdigit()):

print('Onlynumeralsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=ntrfare()elif( n.isalpha()

):
print('Onlynumeralsareallowed(seperatedwithcommas(,)','
\U0001F610')

n=ntrfare()

return n

defmakeadmin():#onlyaexistingadmincanmakeanewadmin

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

print('Thenewadminshould be registerd in indian railways ') print('Enter

the details of new admin ')

nm=username()

af=userid()

qr='select*fromuser_infowhereuser_name=%sanduser_id=%s'az=(nm,af)

d.execute(qr,az)

f=d.fetchall()

rw=d.rowcount

if rw==1 :

forxinf:
ifx[6]=='user':

qr='updateuser_infosetrole="admin"whereuser_name=%sand user_id=%s '

az=(nm,af)

d.execute(qr,az)

conn.commit()

goback()

elifx[6]=='admin':

print('Userwiththegivenidandusernameisalreadyadmin
')

goback()

else:

print("User not found !")

goback()

conn.close()

def goback(): # a function for going

back print('')

print('Type1togoback')

print('Type2 toquittheapplication') print('')


playsound("enterthevalidnumberoutofthenumbersgivenabove
.mp3")

cd=input('1-2 : ')

if cd=='1' :

playsound("goingback.mp3")w

elcometoindianrailways()

elif cd

=='2':

exit()

else :

welcometoindianrailways() def

add_train() : # for admin only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

print('************Welcome**************')prin

t('')

print('Type 1 to see the train details ')print('Type

2 to make a new entry in the table ') print('Type

3 to go back to home page ') print('Type 4 to

quit the application ')


playsound("enter thevalid number outofthenumbersgiven above.mp3")

ab=input('1-4 : ')

print('')

ifab=='1':

playsound("showingtherecordsinthetabletrainsinfo.mp3")print('************

******************records of
trains*********************************')

d.execute('select*fromtrains_info')

c=d.fetchall()

rw=d.rowcount

print('Totalnumbersoftrainare:',rw)

print('')

print("%10s%25s%20s%35s%35s"%('traiid','trainname','source'
,'interstations','destination'))

print('
')

forxinc:

print("%10s%25s%20s%35s%20s"
%(x[0],x[1],x[2],x[4],x[3]))

print('')

goback()
conn.close()

ifab=='2':

importmysql.connectorasmyc

conn=myc.connect(host='localhost',user='root',
passwd='student',database='railway_ticketing_software')

d=conn.cursor()

x=int(input('Entertheno.ofrecordsthatyouwanttoenter
:::::'))

print('')

for f in

range(0,x):

print('')

print('*****************************************')m=

trainid()

n=ntrainname()

o=trsource()

p=trdestination()

q=trinterstations()

r=trfare()

print('*****************************************')

ab='insertintotrains_info(train_id,train_name,source,destination,interstations,fare
)values(%s ,%s,%s ,%s ,%s ,%s )'
va=(m,n,o,p,q,r)

d.execute(ab,va)

f=f+1

conn.commit()

playsound("showingtherecordsinthetabletrainsinfo.mp3")

d.execute('select * from trains_info')

c=d.fetchall()

print("%10s%25s%20s%35s%35s"%('train_id','train_name','source'
,'interstations','destination'))

print('
')

forxinc:

print("%10s%25s%20s%35s%20s"
%(x[0],x[1],x[2],x[4],x[3].center(10,'')))

conn.close()

goback()

elif ab=='3' :

welcometoindianrailways()elif

ab =='4' :

exit()

else:
goback()

defadduser():#foranewusertoregisterinindianrailways

importmysql.connectorasmyc

conn=myc.connect(host='localhost',user='root',
passwd='student',database='railway_ticketing_software')

d=conn.cursor()

playsound("pleaseregisteryourselfinindianrailways.mp3")

print('*****Please register yourself in indian railways*********')

d=conn.cursor()

print('')

print('1forregisteringyourselfinindianrailways')

print('2 for going back to home page ')

print('3forquitingtheapplication')

playsound("enterthevalidnumberout ofthe numbersgivenabove


.mp3")

print('')

xy=input('1-3 : ')

print('')

ifxy=='1':

playsound("enterthenumberofvaluesthatyouwantto enter
.mp3")
x=int(input('Enterthenumberofrecordsthatyouwanttoenter
:::::'))

for f in

range(0,x):

print('')

ua=a()

ub=username()

uc=c()

ud=da()

ue=e()

uf =fa()

t='user'

print('*****************************************')

ab='insert into
user_info(user_id,user_name,user_age,user_gender,user_mobile_no,password,role)
values( %s,%s ,%s ,%s,%s,%s,%s)'

va=(ua,ub,uc,ud,ue,uf,t)

d.execute(ab,va)

f=f+1

conn.commit()

print("-----REGISTEREDININDIANRAILWAYS------
",'\U0001F44D','\U0001F44D')

print('')
goback()elif

xy =='2' :

welcometoindianrailways() elif

xy == '3' :

exit()

else:

goback()

defupdatemanipulatedisplaytables():#todisplayandmanipulatethe
recordsoftrainsinfoandbookinginfo(foradminsonly)

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

print('')

print('1 to display the records of trains_info')

print('2todisplaytherecordsofbooking_info')

print('3to displaythe recordsofboththetables bookinginfoandtrains info')

print('4 to update or delete records')

print('5 to go back')

print('6toquittheapplication')
print('')

playsound("enterthevalidnumberoutofthenumbersgivenabove.mp3") mn=input('1-

6 : ')

print('')

ifmn=='1':#itdisplaystherecordsofthetrains

playsound("showingtherecordsinthetabletrainsinfo.mp3")

print('***********************************records of

trains*****************************')

print('')

d.execute('select*fromtrains_info')

c=d.fetchall()

print("%10s%25s%20s%35s%35s"%('trainid','trainname','source'
,'interstations','destination'))

print('
')

forxinc:

print("%10s%25s%20s%35s%20s"
%(x[0],x[1],x[2],x[4],x[3].center(10,'')))

goback()

ifmn=='2':#itdisplaystherecordsofthebookings
playsound("showingtherecordsinthetablebookingsi

nfo.mp3")d.execute('select*frombooking_info')

f=d.fetchall()

print('*****************************************recordsofbooking
******************************')

print("%10s%15s%20s%25s%15s%15s%25s%25s"
%('booking_id','train_id' ,'user_id','date_of_journey','fare'
,'source','destination','status'))

print('

')

forxinf:

print("%10s%15s%20s%25s%20s%15s%20s
%25s"%(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7].rjust(8,'')))

goback()

ifmn=='3':#itdisplaystherecordsofbookingandtrains

playsound("showingtherecordsinthetablebookingsinfo.mp3")

print('********************records of booking and trains

*******************')

print('')

d.execute('select * frombooking_info ')


f=d.fetchall()

print('***************************recordsofbooking
***********************************')

print("%10s%15s%20s%25s%15s%15s%25s%25s"
%('booking_id','train_id' ,'user_id','date_of_journey','fare'
,'source','destination','status'))

print('

')

forxinf:

print("%10s%15s%20s%25s%20s%15s%20s
%25s"%(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7].rjust(8,'')))

print('')

playsound("showingtherecordsinthetabletrainsinfo.mp3")d.exec

ute('select * from trains_info')

c=d.fetchall()

print('***************************************records
oftrains***********************************')

print("%10s%25s%20s%35s%35s"%('trainid','trainname','source'
,'interstations','destination'))

print('
')

forxinc:
print("%10s%25s%20s%35s%20s"
%(x[0],x[1],x[2],x[4],x[3].center(10,'')))

goback()

conn.close()

elif

mn=='4'

: upde()

elifmn=='5':

welcometoindianrailways() elif

mn == '6' :

exit()else

goback()

deftrain_name():#updatethecolumntrainsnameofthetabletrains info , for


admins only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=ntrainname()

cd=trainid
qr=('select*fromtrains_infowheretrain_id=%s') vl=(cd,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw==1 :

dr=('updatetrains_infosettrain_name=%swheretrain_id=%s')#update the
train name

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

d.execute(qr,vl)

c=d.fetchall()

forxinc:#displaystherecordwithupdatedvalues print(' ')

print('Trainid:',x[0])

print('Train name : ' ,x[1])

print('Sourceofthetrainis:',x[2])

print('Destination of the train is : ' ,

x[3])print('Interstationsofthetrainsare:',x[4])

print('Fare :',x[5])
print(' ............................................................... ')

goback()else:

print('No such train exists ! ', ' \U0001F610')

goback()

defsource():#updatethecolumnsourceofthetabletrainsinfo,for admins only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=ntrsource

cd=trainid()

qr=('select*fromtrains_infowheretrain_id=%s') vl=(cd,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw==1 :
dr=('updatetrains_infosetsource=%swheretrain_id=%s')#updatethe source

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

d.execute(qr,vl)

c=d.fetchall()

forxinc:#displaystherecordwithupdatedvalues print(' ')

print('Trainid:',x[0])

print('Train name : ' ,x[1])

print('Sourceofthetrainis:',x[2])

print('Destination of the train is : ' ,

x[3])print('Interstationsofthetrainsare:',x[4])

print('Fare :',x[5])

print(' ............................................................... ')

goback()else:

print('No such train exists ! ', ' \U0001F610')

goback()
defdestination():#updatethecolumndestinationofthetabletrainsinfo
,foradminsonly

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=ntrdestination()

cd=trainid()

qr=('select*fromtrains_infowheretrain_id=%s') vl=(cd,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

dr=('updatetrains_infosetdestination=%swheretrain_id=%s')#update the
destination

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

d.execute(qr,vl)

c=d.fetchall()
forxinc:#displaystherecordwithupdatedvalues print(' ')

print('Trainid:',x[0])

print('Train name : ' ,x[1])

print('Sourceofthetrainis:',x[2])

print('Destination of the train is : ' ,

x[3])print('Interstationsofthetrainsare:',x[4])

print('Fare :',x[5])

print(' ............................................................... ')

goback()else:

print('No such trains exist !',' \U0001F610')

goback()

def interstations () :#update the column interstations of the table


trainsinfo , for admins only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=ntrinterstations()
cd=trainid()

qr=('select*fromtrains_infowheretrain_id=%s') vl=(cd,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

dr=('update trains_info set interstations= %s where train_id=%s')


#update interstations

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

d.execute(qr,vl)

c=d.fetchall()

forxinc:#displaystherecordwithupdatedvalues print(' ')

print('Trainid:',x[0])

print('Train name : ' ,x[1])

print('Sourceofthetrainis:',x[2])

print('Destination of the train is : ' ,

x[3])print('Interstationsofthetrainsare:',x[4])
print('Fare :',x[5])

print(' ............................................................... ')

goback()else:

print('No such trains exist !',' \U0001F610')

goback()

def fare() :#update the column fare of the table booking info , for admins
only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=ntrfare()

cd=trainid()

qr=('select*fromtrains_infowheretrain_id=%s') vl=(cd,)

d.execute(qr,vl)

c=d.fetchall()

rw=d.rowcount

if rw == 1 :
dr=('updatetrains_infosetfare=%swheretrain_id=%s')#update
fare

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

d.execute(qr,v)

c=d.fetchall()

forxinc:#displaystherecordwithupdatedvalues print('')

print('Trainid:',x[0])

print('Train name : ' ,x[1])

print('Sourceofthetrainis:',x[2])

print('Destination of the train is : ' ,

x[3])print('Interstationsofthetrainsare:',x[4]) print('Fare

:',x[5])

print(' ............................................................... ')

goback()else:

print(' No such train exist ! ', ' \U0001F610')

goback()
def usernameui() :#update the column user name of the table users info,
for admins only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user= 'root',


passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=nusername()

cd=userid()

qr=('select*fromuser_infowhereuser_id=%s')

ab=(cd,)

d.execute(qr,ab)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='admin':

dr=('updateuser_infosetuser_name=%swhereuser_id
=%s')#updateuser'sname

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()
d.execute(qr,ab)

forxind:#displaystherecordwithupdatedvalues print('User id :

',x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('User gender : ',x[3])

print('Usermobileno: ',x[4])

print('Password : ',x[5])

goback()

elifx[6]=='user':

print('Userwiththegivenuseridandusernameisnotregisteredas admin ', '


\U0001F610')

goback()

else:

print('No such admin exist !',' \U0001F610')

goback()

defuserageui():#updatethecolumnuserageofthetableusersinfo,for admins only

importmysql.connectorasmyc
conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=c()

cd=userid()

qr=('select*fromuser_infowhereuser_id=%s')

ab=(cd,)

d.execute(qr,ab)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='admin':

dr='updateuser_infosetuser_age=%swhereuser_id=%s'#updateuser's age

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

qr=('select*fromuser_infowhereuser_id=%s') vl=(cd,)

d.execute(qr,vl)
f=d.fetchall()

forxinf:#displaystherecordwithupdatedvalues print('User id :

',x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('User gender : ',x[3])

print('User mobileno : ',x[4])

print('Password : ',x[5])

goback()

elifx[6]=='user':

print('Userwiththegivenuseridandusernameisnotregisteredas admin ', '


\U0001F610')

goback()

else:

print('No such admin exist !',' \U0001F610')

goback()

def passwordui() :#update the column user age of the table users info , for
admins only

importmysql.connectorasmyc
conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=nfa()

cd=userid()

qr=('select*fromuser_infowhereuser_id=%s')

ab=(cd,)

d.execute(qr,ab)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='admin':

dr=('update user_info set password=%s where user_id=%s ') #


updateuser's age

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

qr=('select*fromuser_infowhereuser_id=%s') vl=(cd,)

d.execute(qr,vl)
f=d.fetchall()

forxinf:#displaystherecordwithupdatedvalues

print('User id : ',x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('User gender : ',x[3])

print('User mobileno : ',x[4])

print('Password : ',x[5])

goback()

elifx[6]=='user':

print('Userwiththegivenuseridandusernameisnotregisteredas admin ', '


\U0001F610')

goback()

else:

print('No such admin exist !',' \U0001F610')

goback()

defusermobilenoui():#updatethecolumnusermobilenumberofthe table users


info , for admins only

importmysql.connectorasmyc
conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=ne()

cd=userid()

qr=('select*fromuser_infowhereuser_id=%s') ab=(cd,)

d.execute(qr,ab)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='admin':

dr=('updateuser_infoset user_mobile_no=%s where user_id=%s') #


update user's mobile number

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

d.execute(qr,ab)

f=d.fetchall()

forxinf:#displaystherecordwithupdatedvalues
print('Userid:',x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('User gender : ',x[3])

print('User mobileno : ',x[4])

print('Password : ',x[5])

goback()

elifx[6]=='user':

print('Userwiththegivenuseridandusernameisnotregisteredas admin ', '


\U0001F610')

goback()

else:

print('No such user exist ! ', ' \U0001F610')

goback()

defdelti():#deletetherecordofthetrainwhosetrainidisgivenbythe admin , for admins


only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()
cd=trainid()

rx=('select*fromtrains_infowheretrain_id=%s') cf=(cd,)

d.execute(rx,cf)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

zx=('deletefromtrains_infowheretrain_id=%s')#deletethetrain's
record

cf=(cd,)

d.execute(zx,cf)

conn.commit()

d.execute('select*fromtrains_info')

c=d.fetchall()

print("%10s%25s%20s%35s%35s"%('trainid','trainname'
,'source','interstations','destination'))

print('
')

forxinc:

print("%10s%25s%20s%35s%20s"
%(x[0],x[1],x[2],x[4],x[3].center(10,'')))

goback()
else:

print('No such train exist !', ' \U0001F610')

goback()

defdelui():#deletetherecordoftheadminwhoseuseridisgiven,for admins only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

cd=userid()

rx=('select*fromuser_infowhereuser_id=%s') cf=(cd,)

d.execute(rx,cf)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

zx=('deletefromuser_infowhereuser_id=%s')#deleteuser'sinfo cf=(cd,)

d.execute(zx,cf)

conn.commit()

d.execute('select * from user_info')


print(' DELETED')

goback()

else:

print('No such user exist ! ', ' \U0001F610')

goback()

defremoveadmin():#anyexistingadmincanonlyremoveaadmin,for admins only

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

print('Theadminshouldberegisterdinindianrailways')af=userid()

nm=username()

qr='select*fromuser_infowhereuser_name=%s anduser_id=%s 'az=(nm,af)

d.execute(qr,az)

f=d.fetchall()

rw=d.rowcount

if rw==1 :

forxinf:
ifx[6]=='admin':

qr='updateuser_infosetrole="user"whereuser_name=%sand user_id=%s '

az=(nm,af)

d.execute(qr,az)

conn.commit()

elifx[6]=='user':

print('Userwithgivenuseridisnotregisteredasadmin','
\U0001F610')

goback()

else:

print("Usernotfound!,Pleaseregisteryourselfinindianrailways",'
\U0001F610')

goback()

defusernameuina():#updatethecolumnusernameinthetableuser info for a


given user id

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=nusername()
cd=userid()

qr=('select*fromuser_infowhereuser_id=%s')

dt=(cd,)

d.execute(qr,dt)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='user':

dr=('updateuser_infosetuser_name=%swhere
user_id=%s')

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

qr=('select*fromuser_infowhereuser_id=%s') dt=(cd,)

d.execute(qr,dt)

f=d.fetchall()for

x in f :

print('')

print('Recordwithupdatedvaluesare:')
print('Userid:',x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('Usergender:',x[3]) print('User

mobile number : ',x[4]) print('User

password:',x[5]) goback()

elifx[6]=='admin':

print('Toupdateyourrecordspleasegotoadminportal','
\U0001F610')

goback()

else:

print('User not found !',' \U0001F610')

goback()

defpasswduina():#updatethecolumnuserpasswordinthetableuser info for a


given user id

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()
nv=nfa()

cd=userid()

dr=('select*fromuser_infowhereuser_id=%s') dt=(cd,)

d.execute(dr,dt)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='user':

dr=('updateuser_infosetpassword=%swhere
user_id=%s')

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

qr=('select*fromuser_infowhereuser_id=%s') dt=(cd,)

d.execute(qr,dt)

f=d.fetchall()for

x in f :

print('')
print('Recordwithupdatedvaluesare:') print('User

id : ' ,x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('Usergender:',x[3])

print('User mobile number : ',x[4])

print('User password:',x[5])

goback()

elifx[6]=='admin':

print('Toupdateyourrecordspleasegotoadminportal
','\U0001F610')

goback()

else:

print('User not found !',' \U0001F610')

goback()

defusermobilenouina():#updatethecolumnusermobilenumberinthe table user


info for a given user id

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')
d=conn.cursor()

nv=ne()

cd=userid()

dr=('select*fromuser_infowhereuser_id=%s') dt=(cd,)

d.execute(dr,dt)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='user':

dr=('updateuser_infosetuser_mobile_no=%swhere
user_id=%s')

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

qr=('select*fromuser_infowhereuser_id=%s')

dt=(cd,)

d.execute(qr,dt)

f=d.fetchall()for

x in f :
print('')

print('Recordwithupdatedvaluesare:') print('User

id : ' ,x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('Usergender:',x[3])

print('User mobile number : ',x[4])

print('User password:',x[5])

goback()

elifx[6]=='admin':

print('Toupdateyourrecordspleasegotoadminportal
','\U0001F610')

goback()

else:

print('User not found !',' \U0001F610')

goback()

defuserageuina():#updatethecolumnuserageinthetableuserinfofora given user id

importmysql.connectorasmyc
conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

nv=nc()

cd=userid()

dr=('select *fromuser_info whereuser_id=%s')

dt=(cd,)

d.execute(dr,dt)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='user':

dr=('updateuser_infosetuser_age=%swhere
user_id=%s')

dt=(nv,cd)

d.execute(dr,dt)

conn.commit()

qr=('select*fromuser_infowhereuser_id=%s') dt=(cd,)

d.execute(qr,dt)
f=d.fetchall()

for x in f :

print('')

print('Recordwithupdatedvaluesare:') print('User

id : ' ,x[0])

print('Username:',x[1])

print('Userage:',x[2])

print('Usergender:',x[3])

print('User mobile number : ',x[4])

print('User password:',x[5])

goback()

elifx[6]=='admin':

print('Toupdateyourrecordspleasegotoadminportal
','\U0001F610')

goback()

else:

print('User not found !',' \U0001F610')

goback()

defupde():#forupdating,deleting,andmanipulatingtherecordsofthe table , for


admins only
importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

print('')

print('1 to manipulate the records of table trains info')

print('2 to manipulate the data of table users

info')print('3 to go back ')

print('4toquittheapplication')

playsound("enterthevalidnumberoutofthenumbersgivenabove
.mp3")

print('')

pq=input('1-4:')

if pq=='1' :

print('')

print('1 to update')

print('2 to delete')

print('3 to go back ')

print('4toquittheapplication')

playsound("enterthevalidnumberoutofthenumbersgivenabove
.mp3")
print('')

qr=input('1-4:')

if qr=='1' :

print('')

print('1 to update train_name')

print('2 to update source')

print('3 to update destination')

print('4 to update interstations')

print('5 to go back')

print('6toquittheapplication')

playsound("enterthevalidnumberoutofthenumbersgivenabove.mp3") gh=input('1-

6 :')

if gh =='1' :

train_name()elif

gh =='2' :

source()elif

gh=='3' :

destination()elif gh

=='4' :

interstations()
elif gh =='5' :

welcometoindianrailways() elif

gh=='6' :

exit()

else:

print('Choosethecorrectoption')

print('')

upde()elif

qr=='2' :

delti()elif

qr=='3' :

welcometoindianrailways() elif

qr == '4' :

exit()

else:

print('Choosethecorrectoption') print('')

upde()elif

pq=='2' :

print('')

print('1toupdate')
print('2 to delete')

print('3 to go back ')

print('4toquittheapplication')

playsound("enterthevalidnumberoutofthenumbersgivenabove.mp3") tv=input('1-4

:')

iftv=='1':

print('1 to user name')

print('2 to user age')

print('3 to user mobile no . ')

print('4 to go back ')

print('5toquittheapplication')

playsound("enterthevalidnumberoutofthenumbersgivenabove.mp3") print('')

ih=input('1-5:')

print('')

if ih=='1' :

usernameui() elif

ih =='2' :

userageui()
elif ih =='3' :

usermobilenoui() elif

ih =='4' :

welcometoindianrailways() elif

ih =='5':

exit()

else:

print('Choosethecorrectoption')

print('')

upde()elif

tv=='2' :

delui()elif

tv=='3' :

welcometoindianrailways() elif

tv =='4' :

exit()

else:

print('Choosethecorrectoption') print('')

upde()elif

pq=='3' :
welcometoindianrailways() elif

pq=='4' :

exit()

else:

print('Choosethecorrectoption')

print('')

upde()

def ticgen(e,f,ti,fo,g,h,i,doj,ax,ay,az) : # generation of ticket

print('')

print("\N{winking face}","\N{winking face}","\N{winking face}","\N{winking


face}",'**ticket booked**',"\N{winking face}","\N{winking face}","\N{winking
face}","\N{winking face}")

print('Source of the train : ',e)

print('Destinationofthetrainis:',f)

print('Train id is:',ti)print('Booking id is

: ', fo)

print('')

print('Source of the journey is : ',g)

print('Destinationofthejourneyis:',h)print('Fa

re is : ',i)

print('Dateofjourneyis:',doj)
print("Passenger'sname : ",ax)

print('Gender : ',ay)

print('Age:',az)

goback()

defbooktble(m,n,o,z,q,r,s,t):#confirmationofbookedticket

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

t='active'

ab='insert into
booking_info(booking_id,train_id,user_id,date_of_journey,fare,source,destination,statu
s) values(%s,%s,%s ,%s,%s,%s,%s,%s)'

va=(m,n,o,z,q,r,s,t)

d.execute(ab,va)

conn.commit()

qr='select booking_id,train_id,user_id,
DATE_FORMAT(date_of_journey,"%y-%m-
%d"),fare,source,destination,status from booking_info
wherebooking_id=%s'

vl=(m,)
d.execute(qr,vl)

c=d.fetchall()for

x in c :

print('Bookingid:',x[0])

print('Trainid:',x[1])

print('User id :',x[2])

print('Date of journey

:',x[3])print('Fare :',x[4])

print('Source:',x[5])

print('Destination:',x[6])

print('Status:',x[7])

bi=x[0]

importre

ci=input('Doyou want to confirm(YES or NO)

:')lenci=len(ci)

dc=ci.upper()

yes='YES'

no='NO'

#iflenci ==2 orlenci ==3: if

dc == 'NO' :

ifre.search(no,dc):
zx=('updatebooking_infosetstatus="cancel"wherebooking
_id=%s')

cf=(bi,)

d.execute(zx,cf)

conn.commit()

print('****Bookingcancelled****')

welcometoindianrailways()

ifdc!='NO'ordc!='YES'

:print('Invalidoption!') print('')

print('Fillyour entries again')

booktic()

elif dc == yes :

ticgen(e,f,ti,fo,g,h,i,doj,ax,ay,az)

def booktic() : # book a ticket

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

ud=userid()

query="select*fromuser_infowhereuser_id=%s"
vals = (ud,)

d.execute(query,vals)

rc=d.rowcount

f=d.fetchall()

rc=d.rowcount

ifrc==1 :

forxinf:

uni=x[1]

ug=x[3]

ua=x[2]

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

d.execute('selectMAX(booking_id)frombooking_info') f=d.fetchall()

forxinf:

ab=x[0]+1 #newbookingid

#print(ab) # to display new booking id

fo=ab

d.execute('select*fromtrains_info')
c=d.fetchall()

print("%10s%25s%20s%35s%35s"%('train_id','train_name'
,'source','interstations','destination'))

print('
')

forxinc:

print("%10s%25s%20s%35s%20s"
%(x[0],x[1],x[2],x[4],x[3].center(10,'')))

print('')print('******************************************************************')

ti=trainid()

print('***************************************************************')

b='select*fromtrains_infowheretrain_id=%s'%(ti,) d.execute(b)

f=d.fetchall()

rw=d.rowcount

if rw==1 :

forxinf:

print('Trainid:',x[0])

print('Trainname:',x[1])

print('Source:',x[2])
print('Destination : ',x[3])

print('Interstations:',x[4])

print('Fare : ',x[5])

a=x[5]

fare=a.split(',')

sum=0

foriinfare:

sum=sum+int(i)

e='select source ,interstations , destination from trains_info


where train_id=%s' % (ti,)

d.execute(e)

f=d.fetchall()

for x in f :

print('')

print(' ............................................................ ')

print('Source of the train is : ' ,x[0])

print('Interstations are : ' ,x[1])

print('Destinationofthetrainis:',x[2])

print(' ................................................................ ')


print('')

ali=[]

ali.append(x[0])

intList=str(x[1]).split(',')

ali.extend(intList)

ali.append(x[2])

conn.close()

bg=len(ali)

x=int(bg)

sz=len(ali)

foriinrange(sz):

print(ali[i],'forrupees',fare[i])

print('')

print('Allthestationsincludingsourceanddestination:',
ali)

print('')

for i in range(0,bg-1) :

print('enter',i+1,'for',ali[i])

print('')

try :
so=int(input('Entersourceforyourjourney(outofnumbersasgivenabove ) : '))

except ValueError

as e : print('Invalid !

') print('')

print('Fillyourentriesagain')

print('')

booktic()try

b=ali[so-1]

except IndexError

as e : print('Invalid !

') print('')

print('Fillyourentriesagain')

print('')

booktic()

print('')

print('***************************************')

for k in range(so,x) :

print('Enter ',k+1,'for',ali[k])

print('***************************************')
try:

e=int(input('Enterthedestinationforyourjourney(outofnumbersasgiven above)
:'))

except ValueError

as e : print('Invalid !

') print('')

print('Fillyourentriesagain')

print('')

booktic()try

fg=ali[e-1]

except IndexError

as e : print('Invalid !

') print('')

print('Fillyourentriesagain')

print('')

booktic()

print('')

ife!=so:

try:

doj=input('Enterdateforyourjourney(YY/MM/DD)')
exceptValueError as

e : print('Invalid ! ')

print('')

print('Fillyourentriesagain')

print('')

booktic() import

datetime

now=datetime.datetime.now()

curdate=now.strftime("%y/%m/%d")currd=str(curdate

#print(currd)#printtoday'sdate if

currd < doj :

ac=0

print('')

forjinrange(so,e)

:ac+=int(fare[j])

#print(ac) # to display the fare

fr=ac

so=ali[0]

de=ali[4]

sou=b
deu=fg

sta='active'

booktble(ab,ti,ud,doj,ac,sou,deu,sta)

ticgen(so,de,ti,ab,sou,deu,fr,doj,uni,ug,ua)

else:

print('Invaliddate')

print('')

print('Fill your entries

again')print('')

booktic()elif

e==so :

print("Source can't be destination")

print('')

print('Fill your entries

again')print('')

booktic()else:

print('Invalid option ','\U0001F614')

print('')

print('Fill your entries

again')print('')
booktic()

else:

print('No such train exists'

,'\U0001F614')goback()

else:

print('Usernotfound,pleaseregisteryourselfinindianrailways','
\U0001F610')

adduser()

defchangeui():

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

a=username()

query="select * from user_info whereuser_name=%s"

vals = (a,)

d.execute(query,vals)

f=d.fetchall()

rc=d.rowcount
ifrc== 1

:forxinf

ifx[6]=='user':

#print(x[5]) # it displays the password

pw=fa()

if pw ==

x[5]:vals

=(a,)

d.execute(query,vals)

f=d.fetchall()

forxinf:

query="select * from user_info whereuser_name=%s"

vals = (a,)

d.execute(query,vals)

f=d.fetchall()

rw=d.rowcount

ifrw ==1:

forxinf:

print('')

print('Userid:',x[0])

print('Username:',x[1])
print('Userage:',x[2])
print('Usergender:',x[3])

print('Usermobilenumber:',x[4])

print('User password :',x[5])print('')

#conn.commit()

conn.close()

print('')

print('1 to update user name ')

print('2toupdatepassword')

print('3toupdateusermobilenumber') print('4

to update user age ')

print('5togoback')

print('6 to quit the application ')

playsound("enterthevalidnumberoutofthe

numbersgivenabove.mp3")

choi=input('1-6 : ')

if choi == '1' :

usernameuina()elif

choi == '2' :

passwduina() elif

choi == '3' :
usermobilenouina()elif

choi == '4' :

userageuina()elif

choi =='5' :

welcometoindianrailways() elif

choi == '6' :

exit()else

print('Invalid option')

print('')

print('Please choose the option again')

changeui()

else:

print('Incorrect!','\U0001F614')

goback()

elifx[6]=='admin':

print("Tomodifyadmin'srecordpleasegotoadminportal,userwithgiven userid
isregistered as admin ", ' \U0001F610')

welcometoindianrailways()

else:

print('')
print('Usernotfound,pleaseregisteryourselfinindianrailways
first')

print('')

adduser()

defcanbook():#cancelstheticket(foradminsalso)

importmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_softw

are' )d=conn.cursor()

import datetime

now=datetime.datetime.now()

a=now.strftime("%y-%m-%d")

#print(a)#displaystoday'sdate try

bi=int(input('Enterbookingid(7digits):'))except

exception as e :

print('Bookingidshouldbenumericonly(7digits)')print('')

canbook()
qr='selectDATE_FORMAT(date_of_journey,"%y-%m-%d")from
booking_info where booking_id=%s'

vl=(bi,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

qr='select*frombooking_infowherebooking_id=%sandstatus="cancel"'vl=(bi,)

d.execute(qr,vl)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

print('\U0001F6AB','\U0001F6AB','\U0001F6AB','\U0001F6AB','Ticketis
already cancelled
','\U0001F6AB','\U0001F6AB','\U0001F6AB','\U0001F6AB')

goback()else:

if(a<x[0]):#comparestoday'sdatewith booking'sdate
zx=('updatebooking_infosetstatus="cancel"where
booking_id=%s')

cf=(bi,)

d.execute(zx,cf)

conn.commit()

print('\U0001F6AB','\U0001F6AB','\U0001F6AB','\U0001F6AB','**bookingcancelled**','\U0001F
6AB','\U0001F6AB','\U0001F6AB','\U0001F6AB')

goback()

else:#iftoday'sdateisgreaterthanbooking'sdatethen,ticketcannotbe cancelled

print('Ticketcannotbecancellednow!') goback()

else:

print('Invalid booking id

','\U0001F614')goback()

def seebook() : # to see your

bookingimportmysql.connector

as myc

conn=myc.connect(host='localhost', user= 'root',


passwd='student',database='railway_ticketing_software')

d=conn.cursor()

a=input('Enterbookingid(7digits):')
qe='selectbooking_id,train_id,date_of_journey,fare,source ,
destination, status,user_name,user_gender,user_age, statusfrom
booking_infobjoinuser_infouwherebooking_id=%sandb.user_id= u.user_id '

br=(a,)

d.execute(qe,br)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

if x[6]==

'active':

print('')

print('Bookingid:',x[0])

print('Train id : ',x[1])

print('Dateofjourney:',x[2])

print('Fare : ',x[3])

print('Source:',x[4])

print('Destination:',x[5])

print('Status:',x[6])

print('Username:',x[7])

print('Usergender:',x[8])
print('User age : ',x[9]) else :

print('Ticketiscancelled')

else:

print('Nosuchbookingidexists','\U0001F614')goback()

defadmin_por():#onlyadminscanonlyaccessthis

moduleimportmysql.connectorasmyc

conn=myc.connect(host='localhost', user=
'root',passwd='student',database='railway_ticketing_software')

d=conn.cursor()

playsound("askadmin.mp3")

poo=str(input('Areyouadmin,EnterYES or NO :')) po=poo.upper()

print('')

ifpo=='NO':

playsound("na.mp3")

welcometoindianrailways()#iftheuserisnotadminthenuserwillgoback to home
page

print('')
elif po == 'YES' :

playsound("askusernamecon.mp3")

nv=username()

playsound("askpasswordcon.mp3")

cd=fa()

dr='select*fromuser_infowhereuser_name=%sandpassword=%s
'

dt=(nv,cd)

d.execute(dr,dt)

f=d.fetchall()

rw=d.rowcount

if rw == 1 :

forxinf:

ifx[6]=='admin':

print('')

print('1toaddtraindetails')

print('2 to manipulate the user and train details ')

print('3 to make a new admin ')

print('4toremoveanexistingadmin') print('5

to go back ')

print('6toquittheapplication')
playsound("enterthevalidnumberoutofthenumbersgivenabove.mp3") cp=input('1-

6 : ')

ifcp=='1':

add_train()elif

cp=='2' :

updatemanipulatedisplaytables() elif

cp == '3' :

makeadmin() elif

cp == '4' :

removeadmin()elifcp

=='5':

welcometoindianrailways()elifcp

=='6':

exit()

else:

print('Invalid option')

print('')

print('Please choose the option again')

admin_por()

elifx[6]=='user':
print('Userwiththegivenuseridisnotregisteredas
admin')

goback()

else:

print('Credentials are incorrect !','\U0001F614')

goback()

else:

print('Invalid option')

print('')

print('Please choose the option again')

admin_por()

def welcometoindianrailways() :

playsound("hello1.mp3")

print('\U0001f686','\U0001f686','\U0001f686','\U0001f686','\U0001f686','\U0001f686','\U0001f6
86','\U0001f686','\U0001f686','\U0001f686','\U00
01f686','Welcome to Indian
railway','\U0001f686','\U0001f686','\U0001f686','\U0001f686','\U0001f686','
\U0001f686','\U0001f686','\U0001f686','\U0001f686','\U0001f686','\U0001f
686')

print('')

print('1toadminportal')
print('2toaddauser(toregisterinindianrailways)') print('3 to

book a ticket ')

print('4 to cancel the booking ')

print('5 to view your booking ')

print('6 tomodify the user record

')print('7 toquit theapplication')

playsound("enterthevalidnumberoutofthenumbersgivenabove
.mp3")

print('')

op=input('1-7:')

print('')

if op=='1' :

admin_por()elif

op == '2' :

adduser()elif

op=='3' :

booktic()elif

op =='4' :

canbook()elif

op =='5' :

seebook()
elifop =='6'

:changeui()

elif

op=='7'

:exit()

else :

print('Invalid option')

print('')

print('Please choose the option again')

welcometoindianrailways()

conn.close()

welcometoindianrailways()
MODULE2:connfunatt
defdatabaserelatedqueries():

importmysql.connectorasmy

conn=my.connect(host='localhost',user='root',passwd='student',database='railway_ticketi
ng_software')

l=conn.cursor()

l.execute('createdatabaserailway_ticketing_software')

l.execute('use railway_ticketing_software')

l.execute('createtabletrains_info\ (train_id

int(5),\

train_name varchar(30),\

source varchar(30) ,\

destination varchar(30) ,\

interstationsvarchar(60),\

fare varchar(29))')
l.execute('createtableuser_info\ (user_id

int(9),\

user_name varchar(30),\

user_ageint(3),\

user_gender char(1),\

user_mobile_nobigint(10),\

password varchar(15),\

rolevarchar(15))')

l.execute('create table booking_info \

(booking_id int(7) , \

train_id int(5) , \user_id

int(9) , \

date_of_journeydate,\

fare int(4) ,\

source varchar(30),\

destination varchar(30),\

status varchar(10))')

print('*************nowdescribingallthethreetables***********')print('')
l.execute('desctrains_info')

for x in l :

print(x)

print('')

l.execute('descuser_info') for

x in l :

print(x)

print('')

l.execute('descbooking_info') for

x in l :

print(x)

conn.close()

importgtts

from playsound import

playsoundimport os

mytext='texttospeechconversion'

language = 'en'

output=gtts.gTTS(text=mytext,lang=language,slow='false')output

= gtts.gTTS(" welcome to indian railways")output.save('hello.mp3')


playsound("hello.mp3")

output=gtts.gTTS("showingtherecordsinthetabletrainsinfo")

output.save('showingtherecordsinthetabletrainsinfo.mp3')playsound("showingtherecor

dsinthetabletrainsinfo.mp3")

output = gtts.gTTS("are you admin")

output.save('askadmin.mp3')

playsound("askadmin.mp3")

output=gtts.gTTS("enterusername")

output.save('askusernamecon.mp3')playso

und("askusernamecon.mp3")

output = gtts.gTTS("enter the

password")output.save('askpasswordcon.mp3')pl

aysound("askpasswordcon.mp3")

output=gtts.gTTS("enterbacktogoback")
output.save('goingback.mp3')

playsound("goingback.mp3")

output=gtts.gTTS("pleaseregisteryourselfinindianrailways")output.save('pleaseregister

yourselfinindianrailways.mp3')playsound("pleaseregister yourself in indian

railways.mp3")

output=gtts.gTTS("enterthenumberofvaluesthatyouwanttoenter
")

output.save('enterthenumberofvaluesthatyouwanttoenter.mp3')playsound("enterthen

umberofvaluesthatyouwanttoenter.mp3")

output=gtts.gTTS("incorrect")

output.save('wrong.mp3')

playsound("wrong.mp3")

output=gtts.gTTS("sorry,youarenotadmensoyoucannotaccessthis module ")

output.save('na.mp3')

playsound("na.mp3")
output=gtts.gTTS("showingtherecordsinthetablebookingsinfo")

output.save('showingtherecordsinthetablebookingsinfo.mp3')

playsound("showingtherecordsinthetablebookingsinfo.mp3")

output=gtts.gTTS("enterthevalidnumberoutofthenumbersgiven above ")

output.save('enter thevalidnumberoutofthenumbersgiven above


.mp3')

playsound("enterthevalidnumberout ofthe numbersgivenabove


.mp3")
SCREENSHOTS
OF
OUTPUTS:
Incorrectusernameandincorrectuserpassword
Incorrectusernameandcorrectpassword

Correctusernameandincorrectpassword
Correctusernameandcorrectuserpassword
Bookingticket
Afterbookingtheticket
Aftercancellingtheticket
USERTABLEAFTEREDITTING
SCREENSOTS
OF
MySQL:
USER TABLE BEFORE EDITING

USER TABLE AFTER EDITING


TRAIN TABLE BEFORE EDITING

TRAIN TABLE AFTER EDITING


References
1. Subject teacher
2. Internet
Thankyou

You might also like