Final
Final
5|Page
S.No. Topic Page No.
1 Acknowledgement
2 Index
3 Introduction
5 MySQL Database
6 Outputs
7 Bibliography
Acknowledgement
I am immensely grateful for the guidance and support I have
received during the development of this Railway Reservation
System project. First and foremost, I would like to express my
heartfelt thanks to my project guide, [Supervisor's Name], for their
invaluable insights, constant encouragement, and constructive
feedback throughout the project. Their expertise and patience
made it possible to overcome the challenges faced during each
phase of the development.
I am also grateful to [Institution/Organization Name] and our faculty
members, who provided me with the resources and knowledge
necessary to carry out this project successfully. Their assistance
and encouragement were instrumental in shaping the project and
achieving its objectives.
Additionally, I would like to acknowledge the support of my friends
and classmates, whose feedback and suggestions helped me
improve various aspects of the project. Their motivation kept me
focused and driven throughout the entire process.
Finally, I am thankful to my family for their continuous
encouragement and support. This project would not have been
possible without their understanding and belief in my abilities.
Thank you all for making this project a rewarding learning
experience.
7|Page
INTRODUCTION
The project RAILWAY RESERVATION SYSTEM
Objectives of the Project
1. Administrative EmpowermentThe core objectives of our
project are multi-faceted, addressing the intricate needs of
both administrators and passengers within the railway
ecosystem.
Administrative Functions
The Admin Panel, a focal point of the system, equips
administrators with indispensable tools:
6|Page
name, origin, destination, journey distance, journey time,
seat availability, and fares.
Update Train Details: The system allows administrators to
modify existing train details, adapting to dynamic demands
and operational changes. This includes updating seat
availability, journey details, and fare information.
Cancel Train: In response to operational constraints or changing
demands, administrators have the authority to cancel trains,
ensuring flexibility and adaptability in the system.
User Interaction
User Login: The system provides a secure login interface for
registered users, requiring user ID and password for access.
Forgot User ID: Users can retrieve forgotten user IDs
through their registered email addresses, enhancing user
experience and reducing barriers to access.
9|Page
Train Search: Users can search for trains based on origin
and destination, providing comprehensive details about
available trains, schedules, seat availability, and fares. Book
Tickets: The system facilitates the ticket booking process,
allowing users to select trains, classes, and passengers for
reservation.
Cancel Tickets: A streamlined process enables users to
cancel booked tickets, providing flexibility and convenience
in managing travel plans.
Forgot User ID
The `forgot_user_id()` function provides a mechanism for
users to retrieve their registered user IDs via email
verification, ensuring a smooth user experience.
10 | P a g e
Admin Password Verification
The `adminpassword()` function implements a secure
password system for accessing the admin panel, ensuring
restricted access and system security.
Train Search
The `Train_Search()` function allows users to search for
trains based on origin and destination, providing detailed
information about available trains.
Book Tickets
The `Book_Ticket(uid)` function simulates the ticket booking
process, allowing users to select trains, classes, and
passengers for reservation.
11 | P a g e
Cancel Tickets
The `Cancel_Ticket()` function facilitates the cancellation of
booked tickets, showcasing the system's ability to handle
modifications to user bookings.
PyTHON
SOURCE
CODE: 12 | P a g e
1. 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()
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
13 | P a g e
30. def old_user():
31. dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
32. co=dbo.cursor()
33. print("\n---------------------------------------------------------------\n")
34. uid=input("Enter your user id: ")
35. co.execute("select user_id from user where user_id like '{}'".format(uid))
36. b=co.fetchall() 37. c=len(b)
38. if c==0:
39. print("---------------- Your given id is not registered -----------------")
40. print("\n------------------------------------------------------------------\n")
41. print("1. Try again")
42. print("2. Forgot user id")
43. print("3. Register as a new user")
44. choose=int(input("Choose an option from above: "))
45. if choose==1:
46. old_user() 47. elif choose==2:
48.
forgot_user_id()
49. elif choose==3:
50. new_user() 51.
else:
52. pas=input("Enter your password: ")
53. co.execute("select password from user where password like '{}'".format(pas))
54. n=co.fetchall() 55. for i in n:
56. if pas==(i[0]):
a. print("\n---------------------------------------------------------------\n")
b. print("-----------Welcome back sir/ma'am what's your plan Today??---------\n") c.
passenger_panel(uid)
i. #ADD TRAIN
78. def add_train():
79. dbo=con.connect(host="localhost",user="root",password="admin",database="t
rain_ 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()
15 | P a g e
i. #UPDATE TRAIN TABLE
99. def update_details():
100. dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
101. co=dbo.cursor()
102. print("---------------------------------------------------------------------")
103. print("******Welcome to update train system******")
104. print("1. Update train no")
105. print("2. Update train name")
106. print("3. Update train origin")
107. print("4. Update train destination")
108. print("5. Update journey dist")
109. print("6. Update available days")
110. print("7. Update journey time")
111. print("8. Update no of seats in AC")
112. print("9. Update no of seats in SL")
113. print("10. Update no of seats in GEN")
114. print("11. Update price of AC")
115. print("12. Update price of SL")
116. print("13. Update price of GEN")
117. print("14. Exit")
118. x=int(input("Enter your choice to use: "))
16 | P a g e
133. tno=int(input("Enter train no whose name you want to update: "))
134. tname=input("Enter updated train name: ")
135. co.execute("update train_schedule set train_name='{}' where train_no={}".
format(tname,tno))
136. print("*******UPDATED SUCCESSFULLY********")
137. print("---------------------------------------------------------------------")
138. dbo.commit()
139. return
17 | P a g e
166. print("*******UPDATED SUCCESSFULLY********")
167. print("---------------------------------------------------------------------")
168. dbo.commit()
169. return
20 | P a g e
i. #ADMIN PANEL OPTIONS 261.
def admin_panel():
262. while True:
263. try:
264. print("---------------------------------------------------------------------")
265. print("******Welcome to admin panel******")
266. print("1. Add train")
267. print("2. Update details")
268. print("3. Cancel Train")
269. print("4. Log out")
270. opt=int(input("Choose your option: ")) 271. if opt==1:
a. add_train()
272. elif opt==2:
a. update_details() 273.
elif opt==3:
a. cancel_train() 274.
elif opt==4:
a. print("**********You are out of admin panel***********")
b. print("---------------------------------------------------------------------")
c. main_menu()
275. except InvalidOptionError as e:
276. print(f"Error: {e}") 277. except:
278. print("**********Choose a correct option***********")
279. print("---------------------------------------------------------------------")
21 | P a g e
296. print("Seats in sl: ",a[0][7])
297. print("Seats in GEN: ",a[0][8])
298. print("Fare of ac1: ",a[0][9])
299. print("Fare of sl: ",a[0][10])
300. print("Fare of gen: ",a[0][11])
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:
319. a=co.execute("select ac1_fare from
train_schedule where train_no={}".format(trainno))
320. b=co.fetchall() 321. print(b[0][0]) 322. elif
typ==2:
323. a=co.execute("select sl_fare from
train_schedule where train_no={}".format(trainno))
324. b=co.fetchall() 325. print(b[0][0]) 326. elif
typ==3:
327. a=co.execute("select gen_fare from train_schedule where
train_no={}".format(trainno))
328. b=co.fetchall()
329. print(b[0][0])
330. for i in range (tcktno):
331. cus1=input("Enter customer name: ")
332. age=int(input("Enter your age: "))
333. print("--------------- For gender M=Male, F=Female, O=Other ------------------")
22 | P a g e
334. gender=input("Enter your gender: ")
335. j=random.randint(100000,999999)
336. print("Your PNR no is: ",j)
337. cnf="Confirmed"
338. p=b[0][0]
339. co.execute("insert into booked_tickets values
('{}',{},{},'{}',{},'{}',{},'{}')".format(uid,j,trainno,cus1,age,gender,p,cnf))
340. p=b[0][0]
341. amt=tcktno*p
342. print("Your total ticket price is: ",amt)
343. dbo.commit()
388. main_menu()
MySQl
DATAbASE:
24 | P a g e
:
TRAIN TABLE
PASSENGER LIST :
USER DETAILS :
25 | P a g e
BOOKED_TICKETS:
26 | P a g e
OUTPUTS:
TRAIN RESERvATION MAIN PAgE:
27 | P a g e
THE ADMIN lOgIN PANEl:
CANCEl TICKET:
28 | P a g e
bOOKINg TICKETS :
SEARCH TRAIN:
29 | P a g e
30 | P a g e
bIblIOgRAPHy:
1. CLASS 11th& 12th Computer
Science Book
(SUMITA ARORA)
2.PYTHON
https://www.python.org/
3.MySQL https://www.mysql.com/
4.KV Coders https://kvcoders.in
79874: 5. IRCTC:
https://www.irctc.co.in/nget/
train-search
31 | P a g e