0% found this document useful (0 votes)
9 views19 pages

Python-Based Railway Reservation System

The document outlines the development of an Online Railway Reservation System (O.R.R.S) using Python and MySQL, detailing its features, advantages, and limitations. It explains Python's modes of operation, advantages as a programming language, and the system's functionalities including ticket booking, cancellation, and database management. The project serves as a foundational model for railway booking systems and emphasizes the importance of technology in modernizing ticket booking processes.
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)
9 views19 pages

Python-Based Railway Reservation System

The document outlines the development of an Online Railway Reservation System (O.R.R.S) using Python and MySQL, detailing its features, advantages, and limitations. It explains Python's modes of operation, advantages as a programming language, and the system's functionalities including ticket booking, cancellation, and database management. The project serves as a foundational model for railway booking systems and emphasizes the importance of technology in modernizing ticket booking processes.
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

TABLE OF CONTENTS

[Link] PARTICULARS PAGE No


1 Introduction to 2
python
2 Modes of working in 3
python
3 Advantages of python 4
4 Online Railway 5
Reservation System
5 Scope of railway 6
reservation system
6 Advantages of 7
railway reservation
system
7 Limitations 7
8 Source code 8
9 Output window 16
10 Bibliography 18

5
INTRODUCTION TO PYTHON

Python programming language was developed by Guido Van Rossum in


February 1991. This programming language was named after the famous BBC
comedy show names Monty Python’s Flying Circus. Python is a interpreted
language.

Python is influenced with two programming languages

ABC language

Modula-3

6
Modes of working in python:

Interactive mode:

Also called as “IMMEDIATE MODE”. This mode does not Commands in the
form of a program and also the output is sandwiched between commands . It is
suitable for testing code.

Script mode:

It is useful for creating programs . User has to save the program and then run the
program where the output i

7
Advantages of Python:
1. EASY TO USE:

Python is compact and very easy to use object-oriented language with very
simple syntax rules .It is a very high-level language and highly programmer
friendly.

2. INTERPRETED LANGUAGE:

Python is a interpreted language. It makes python an easy to debug language


and it is suitable for beginners to advanced users.

3. CROSS-PLATFORM LANGUAGE:

Python can run equally well on variety of platforms like Window, Linux,
Macintosh and many more. Thus, python is a portable language.

4. FREE AND OPEN SOURCE:

Python is freely available with its source code.

5. VARIETY OF USAGE APPLICATION:

Python has evolved into a powerful, complete and useful language. Python is
being used in many Fields and application, some are: Graphical User Interface,
Scripting, etc...

6. AVAILABILITY OF LIBRARIES:

There are over 137,000 python libraries present today and they play a vital role
in developing machine learning, data science,data visualization,image and data
manipulation application.

8
Online Railway Reservation System (O.R.R.S)

This project is a console-based Railway Reservation System developed using


Python and MySQL. It provides basic functionality to simulate train ticket
booking in a railway [Link] system connects to a MySQL database to store
and manage data about trains and reservations

This project demonstrates the use of:

[Link]’s [Link] for database connectivity

[Link] queries for creating, reading, updating, and deleting records (CRUD)

[Link] error handling and user input validation

It serves as a foundational model for understanding how railway booking


systems work and can be extended into more advanced systems with features
like user authentication, payment integration, or a graphical interface.

9
Scope of the Railway Reservation System
The Railway Reservation System is designed to simplify and automate the
process of booking train tickets. The scope of this system includes:

1. Train Management

The system maintains a list of trains, including their names, source and
destination stations, and available seats.

2. Ticket Booking

Passengers can book tickets by selecting a train and specifying the number of
seats. The system updates seat availability in real time.

3. Reservation Records

All reservations are stored in the database and can be viewed with details like
passenger name, train, and seats booked.

4. Cancellation of Tickets

Users can cancel a reservation, and the system automatically adjusts the seat
availability for the corresponding train.

5. Database Integration

The use of MySQL ensures persistent storage and efficient data handling,
enabling CRUD operations on train and reservation records.

6. User Interaction

A simple, text-based user interface allows users to interact with the system
easily.

Other scopes of railway reservation system are :

• Tour packages

• Goods transportation

• Hotel and Catering facilities

• Features for booking a flight or any other mode of transport

10
Advantages of Railway Reservation System
[Link] 24/7

2. Reservation can be minimised anywhere

3. Easier to manage

4. Online booking system saves a lot of time

Limitations
• No user login or authentication

• No support for payment integration

•No train schedules or classes (e.g., sleeper, AC)

11
Source Code
import [Link]

from [Link] import Error

def create_connection():

try:

conn = [Link](

host='localhost',

user='root',

password='BalM5@2024',

database='railway_db'

return conn

except Error as e:

print("Error connecting to MySQL:", e)

return None

def initialize_db(conn):

cursor = [Link]()

[Link]("CREATE DATABASE IF NOT EXISTS railway_db")

[Link]("USE railway_db")

[Link]("""

CREATE TABLE IF NOT EXISTS trains (

train_id INT AUTO_INCREMENT PRIMARY KEY,

12
name VARCHAR(100) NOT NULL,

source VARCHAR(50) NOT NULL,

destination VARCHAR(50) NOT NULL,

seats INT NOT NULL

)""")

[Link]("""

CREATE TABLE IF NOT EXISTS reservations (

reservation_id INT AUTO_INCREMENT PRIMARY KEY,

train_id INT,

passenger_name VARCHAR(100),

seats_booked INT,

FOREIGN KEY (train_id) REFERENCES trains(train_id)

)""")

[Link]("SELECT COUNT(*) FROM trains")

if [Link]()[0] == 0:

trains = [

('Express 101', 'CHENNAI', 'TIRUCHIRAPPALLI', 100),

('Express 202', 'TIRUCHIRAPPALLI', 'TIRUVANNAMALAI', 120),

('Express 303', 'CHENNAI', 'TIRUVANNAMALAI', 90),

[Link]("INSERT INTO trains (name, source, destination,


seats) VALUES (%s,%s,%s,%s)", trains)

[Link]()

13
def update_city_names(conn):

cursor = [Link]()

updates = [

("CityA", "CHENNAI"),

("CityB", "TIRUCHIRAPPALLI"),

("CityC", "TIRUVANNAMALAI")

for old, new in updates:

[Link]("UPDATE trains SET source = %s WHERE source = %s",


(new, old))

[Link]("UPDATE trains SET destination = %s WHERE


destination = %s", (new, old))

[Link]()

print("City names updated to new values.\n")

def view_trains(conn):

cursor = [Link]()

[Link]("SELECT * FROM trains")

trains = [Link]()

print("\nAvailable Trains:")

print("ID | Name | Source | Destination | Seats Available")

for t in trains:

print(f"{t[0]:<3}| {t[1]:<11} | {t[2]:<18} | {t[3]:<18} | {t[4]}")

14
def book_ticket(conn):

view_trains(conn)

try:

train_id = int(input("Enter Train ID to book: "))

passenger = input("Enter Passenger Name: ").strip()

seats_req = int(input("Enter Number of Seats: "))

except ValueError:

print("Invalid input. Try again.")

return

if seats_req <= 0 or not passenger:

print("Invalid number of seats or empty name.")

return

cursor = [Link]()

[Link]("SELECT seats FROM trains WHERE train_id=%s",


(train_id,))

result = [Link]()

if not result:

print("Invalid Train ID.")

return

seats_avail = result[0]

if seats_req > seats_avail:

print("Not enough seats available.")

return

15
[Link]("UPDATE trains SET seats = seats - %s WHERE train_id =
%s", (seats_req, train_id))

[Link]("INSERT INTO reservations (train_id, passenger_name,


seats_booked) VALUES (%s, %s, %s)",

(train_id, passenger, seats_req))

[Link]()

print("Ticket booked successfully!")

def view_reservations(conn):

cursor = [Link]()

[Link]("""SELECT r.reservation_id, [Link], r.passenger_name,


r.seats_booked

FROM reservations r

JOIN trains t ON r.train_id = t.train_id""")

bookings = [Link]()

if not bookings:

print("No reservations found.")

return

print("\nYour Reservations:")

print("ResID | Train Name | Passenger | Seats Booked")

for b in bookings:

print(f"{b[0]:<5} | {b[1]:<11} | {b[2]:<16} | {b[3]}")

16
def cancel_reservation(conn):

view_reservations(conn)

try:

res_id = int(input("Enter Reservation ID to cancel: "))

except ValueError:

print("Invalid input. Try again.")

return

cursor = [Link]()

[Link]("SELECT train_id, seats_booked FROM reservations


WHERE reservation_id = %s", (res_id,))

result = [Link]()

if not result:

print("Reservation not found.")

return

train_id, seats_booked = result

[Link]("DELETE FROM reservations WHERE reservation_id = %s",


(res_id,))

[Link]("UPDATE trains SET seats = seats + %s WHERE train_id =


%s", (seats_booked, train_id))

[Link]()

print("Reservation cancelled successfully.")

17
def main():

conn = create_connection()

if not conn:

return

initialize_db(conn)

update_city_names(conn)

while True:

print("-"*117)

print("ONLINE RAILWAY RESERVATION SYSTEM (O.R.R.S)")

print("-"*117)

print("1. View Trains")

print("2. Book Ticket")

print("3. View Reservations")

print("4. Cancel Reservation")

print("5. Exit")

choice = input("Enter choice: ")

if choice == '1':

view_trains(conn)

elif choice == '2':

book_ticket(conn)

18
elif choice == '3':

view_reservations(conn)

elif choice == '4':

cancel_reservation(conn)

elif choice == '5':

print("Goodbye!")

break

else:

print("Invalid choice, try again.")

if __name__ == "__main__":

try:

main()

except KeyboardInterrupt:

print("\nExited by user.")

19
Output screen
Choice window

If choice 1 was chosen

If choice 2 was chosen

20
If choice 3 was chosen

If choice 4 was chosen

If choice 5 was chosen

21
Conclusion
The Online Railway Reservation System developed using Python and MySQL
successfully demonstrates how technology can simplify and modernize the
ticket booking process. The project provides users with an efficient platform to
search trains, check availability, book or cancel tickets, and manage passenger
information in a user-friendly interface.

By integrating Python’s front-end logic with MySQL’s robust database


management, the system ensures data accuracy, security, and faster processing
of transactions. This project also highlights the importance of database
connectivity, data validation, and real-time record management in modern
applications.

Overall, the system achieves its goal of automating manual railway reservation
processes, reducing human errors, saving time, and improving customer
convenience. It can be further enhanced by adding features like online payment
integration, seat selection, and a web-based interface for broader accessibility.

22
Bibliography
• Computer Science with Python-Class XI by Sumita

• [Link]

• [Link]

• [Link]

23

You might also like