Untitled Document
Untitled Document
def adminpassword():
password=(input("Enter your password: "))
if password=="CLASS12CS ":
print("******************Access Granted********************")
print(" ------------------------------------------------------------------- ")
admin_panel()
else:
print("***************ACCESS NOT GRANTED ENTER CORRECT PASSWORD************")
print("----------------------------------------------------------------------")
adminpassword()
def add_train():
dbo=con.connect(host="localhost",user="root", password="admin",
database="train_reservation")
co=dbo.cursor()
print(" ------------------------------------------------------------------- ")
a=int(input("Enter train no: "))
b=input("Enter train name: ")
c=input("Enter train origin: ")
d=input("Enter train destination: ")
e=int(input("Enter train journey distance: "))
g=input("Enter train journey time: ")
h=int(input("Enter no of seats in AC: "))
i=int(input("Enter no of seats in SL: "))
j=int(input("Enter no of seats in GEN: "))
k=int(input("Enter price of AC: "))
i=int(input("Enter price of SL: "))
m=int(input("Enter price of GEN: "))
n=input("Enter days available: ")
print(" ------------------------------------------------------------------- ")
co.execute("insert into train_schedule values
(‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’)".format(a,b,c,d,e,g,h,i,j,k,l,m,n))
print("*********You have added a new train details successfully************")
dbo.commit()
def update_details():
dbo=con.connect(host="localhost", user="root", password="admin", database=
"train_reservation")
co-dbo.cursor()
print(" ------------------------------------------------------------------- ")
print("******Welcome to update train system******")
print("1. Update train no")
print("2. Update train name")
print("3. Update train origin")
print("4. Update train destination")
print("5. Update journey rney dist")
print("6. Update available days ")
.print("7. Update journey time")
print("8. Update no of seats in AC")
print("9. Update no of seats in SL")
print("10. Update no of seats in GEN")
print("11. Update price of AC")
print("12. Update price of SL")
print("13. Update price of GEN")
print("14. Exit")
x=int(input("Enter your choice to use: "))
while True:
i. # To Update train no
if x==1:
print(" ------------------------------------------------------------------- ")
print("**********YOU ARE GOING TO UPDATE TRAIN NO***********")
tname=input("Enter train name whose no you want to update: ")
tno=int(input("Enter updated train no: "))
co.execute("update train_schedule set train_no={} where train_name='{}'".
format(tno,tname))
print("*******UPDATED SUCCESSFULLY********")
print(" ------------------------------------------------------------------- ")
dbo.commit()
return
elif x==6:
print(" ------------------------------------------------------------------- ")
print("**********YOU ARE GOING TO UPDATE AVAILABLE DAYS***********")
tno=int(input("Enter train no whose avl_days you want to update: "))
tad=input("Enter updated available days: ")
co.execute("update train_schedule set avl_days ='{}' where train_no={}".
format(tad,tno))
print("*******UPDATED SUCCESSFULLY********")
print(" ------------------------------------------------------------------- ")
dbo.commit()
return
i. #CANCEL TRAIN
def cancel_train():
dbo=con.connect(host="localhost", user="root", password="admin",
database="train_reservation")
co=dbo.cursor()
ct=int(input("enter train no which you want to cancel: "))
co.execute("delete from train_schedule where train_no={}".format(ct))
dbo.commit()
print("*********** Train cancelled Successfully ****************")
i. #BOOK TICKETS
def Book Ticket(uid):
dbo=con.connect(host="localhost", user= "root", password="admin", database=
"train_reservation")
co=dbo.cursor()
print("THIS IS OUR ALL TRAINS AVAILABLE \n—----------------------------------------------------")
op="select train_no,train_name,origin, destination from train_schedule"
co.execute(op)
r=co.fetchall()
columns=[i[0] for i in co.description]
print(tabulate(r,headers=columns,tablefmt="fancy_grid"))
print(" -------------------------------------------------------------------\n\n ")
trainno=int(input("Enter your Train no: "))
tcktno=int(input("Enter no of seats you want to book: "))
print("1. AC TICKET")
print("2. SL TICKET")
print("3. GEN TICKET")
typ=int(input("Enter your choice of class: "))
if typ==1:
a=co.execute("select ac1_fare from train_schedule where train_no={}".format(trainno))
b=co.fetchall()
print(b[0][0])
elif typ==2:
a=co.execute("select sl_fare from train_schedule where train_no={}".format(trainno))
b=co.fetchall()
print(b[0][0])
elif typ==3:
a=co.execute("select gen_fare from train_schedule where train_no={}".format(trainno))
b=co.fetchall()
print(b[0][0])
for i in range (tcktno):
cus1=input("Enter customer name: ")
age=int(input("Enter your age: "))
print("--------------- For gender M=Male, F=Female, O=Other ------------------")
gender=input("Enter your gender: ")
j=random.randint(100000,999999)
print("Your PNR no is: ",j)
cnf="Confirmed"
p=b[0][0]
co.execute("insert into booked_tickets values(‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’,‘{}’, '{}')".format(uid,j,trainno,
cus1, age, gender,p,cnf))
p=b[0][0]
amt=tcktno*p
print("Your total ticket price is: ",amt)
dbo.commit()
def Cancel_Ticket():
dbo=con.connect(host="localhost",user="root",passwor="admin",database="train_reservation")
co=dbo.cursor()
pnr=int(input("enter pnr no. you want to cancel: "))
co.execute("delete from booked_tickets where pnr_no={}".format(pnr))
dbo.commit()
print("*********** Your ticket cancelled Successfully ****************")
1. #PASSENGER PANEL
def passenger_panel(uid):
dbo=con.connect(host="localhost", user= "root", password="admin", database=
"train_reservation")
co=dbo.cursor()
while True:
print(" ------------------------------------------------------------------- ")
print("********Welcome to passenger panel************)
print("1. Train Search")
print("2. Book Ticket")
print("3. Cancel Ticket")
print("4. Log out")
choic=int(input("Enter your choice to use: "))
if choic==1:
Train_Search()
elif choic==2:
Book_Ticket(uid)
elif choic==3:
Cancel_Ticket()
elif choic==4:
main_menu()
i. #Panel functions
def main_menu():
print(" ------------------------------------------------------------------- ")
print("********WELCOME TO TRAIN RESERVATION SYSTEM**********”)
print("1. Admin panel")
print("2. Passenger panel")
print("3. Exit")
ch=int(input("Enter your choice: "))
while True:
if ch==1:
adminpassword()
elif ch==2:
user_panel()
elif ch==3:
print("***** Thank You for using reservation system*****")
print(" ------------------------------------------------------------------- ")
break
main_menu()