cp2024
cp2024
cp2024
import random
2. from tabulate import tabulate
3. import mysql.connector as con
4.
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
5. co=dbo.cursor()
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
8. co=dbo.cursor()
9. import random
10. pid=random.randint(0,1000)*10
11. print(" ")
12. print(" \n Welcome to our reservation system \n Register Yourself here to use
our system")
13. uid=input("Enter your user id: ")
14. name=input("Enter your name: ")
15. pno=input("Enter your phone no: ")
16. eid=input("Enter your email_id: ")
17. pwd=input("Enter your password: ")
18. co.execute("insert into user values ('{}',{},'{}',
{},'{}','{}')".format(uid,pid,name,pno,eid,pwd))
19. print("************* Congratulations!!! Your id is successfully created
**************")
20. print(" ")
21. dbo.commit()
i. #FORGET USER ID
22. def forgot_user_id():
23.
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
24. co=dbo.cursor()
25. email=input("Enter your registered email: ")
26. co.execute("select user_id from user where email_id like '{}'".format(email))
27. emel=co.fetchall()
28. for i in emel:
29. print("Your user_id is: ",(i[0]))
i. # old user id
30. def old_user():
31.
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
32. co=dbo.cursor()
i. #ADD TRAIN
78. def add_train():
79.
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
80. co=dbo.cursor()
81. print(" ")
82. a=int(input("Enter train no: "))
83. b=input("Enter train name: ")
84. c=input("Enter train origin: ")
85. d=input("Enter train destination: ")
86. e=int(input("Enter train journey distance: "))
87. g=input("Enter train journey time: ")
88. h=int(input("Enter no of seats in AC: "))
89. i=int(input("Enter no of seats in SL: "))
90. j=int(input("Enter no of seats in GEN: "))
91. k=int(input("Enter price of AC: "))
92. l=int(input("Enter price of SL: "))
93. m=int(input("Enter price of GEN: "))
94. n=input("Enter days available: ")
95. print(" ")
96. co.execute("insert into train_schedule values ({},'{}','{}','{}',{},'{}',{},
{},{},{},{},{},'{}')".format(a,b,c,d,e,g,h,i,j,k,l,m,n))
97. print("*********You have added a new train details successfully************")
98. dbo.commit()
179. return
i. #CANCEL TRAIN
254. def cancel_train():
255. dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
256. co=dbo.cursor()
257. ct=int(input("enter train no which you want to cancel: "))
258. co.execute("delete from train_schedule where train_no={}".format(ct))
259. dbo.commit()
260. print("*********** Train cancelled Successfully ****************")
273. a. update_details()
elif opt==3:
a. cancel_train()
274.
a. elif opt==4:
print("**********You are out of admin panel***********")
b. print(" ")
275. c. main_menu()
except InvalidOptionError as e:
276. print(f"Error: {e}")
277. except:
278. print("**********Choose a correct option***********")
279. print(" ")
301. dbo.commit()
i. #BOOK TICKETS
302. def Book_Ticket(uid):
303. dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
304. co=dbo.cursor()
305. print("THIS IS OUR ALL TRAINS AVAILABLE \n
---------------------------------------------
- ")
306. op="select train_no,train_name,origin,destination from train_schedule"
307. co.execute(op)
308. r=co.fetchall()
309. columns=[i[0] for i in co.description]
310. print(tabulate(r,headers=columns,tablefmt="fancy_grid"))
311. print(" \n\n")
312. trainno=int(input("Enter your Train no: "))
313. tcktno=int(input("Enter no of seats you want to book: "))
314. print("1. AC TICKET")
315. print("2. SL TICKET")
316. print("3. GEN TICKET")
317. typ=int(input("Enter your choice of class: "))
318. if typ==1:
i. #PASSENGER PANEL
351. def passenger_panel(uid):
352. dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
353. co=dbo.cursor()
354. while True:
355. print(" ")
i. #Panel functions
372. def main_menu():
373. print(" ")
374. print("********WELCOME TO TRAIN RESERVATION SYSTEM********")
375. print("1. Admin panel")
376. print("2. Passenger panel")
377. print("3. Exit")
378. ch=int(input("Enter your choice: "))
379. while True:
380. if ch==1:
381. adminpassword()
382. elif ch==2:
383. user_panel()
384. elif ch==3:
385. print("***** Thank You for using reservation system*****")
386. print(" ")
387. break
388. main_menu()