OM Project Report
OM Project Report
1
Dr. Virendra Swarup Education Centre,
N-Block, Kidwai Nagar, Kanpur
CERTIFICATE
This is to certify that (name of student) of class XII-B has prepared the report
on the project titled ‘Railway Reservation System’. This report is the result of
his/her efforts and endeavours. The report is found worthy of acceptance as
final project report for the subject Computer Science. The report has been
prepared under the guidance of P.G.T. Computer Science, Mr. Rajat Valecha
within the stipulated time as prescribed by CBSE.
(External Examiner)
2
Acknowledgement
3
Declaration
We declare that the work presented in this project titled “Railway Reservation
System”, submitted to Mr. Rajat Valecha, P.G.T. Computer Science. We 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.
4
Introduction
5
Objective
6
Database Tables
7
Source Code
import mysql.connector
def admin_login():
password = input("Enter admin password: ")
return password == "admin123"
def add_train():
train_name = input("Enter Train Name: ")
source = input("Enter Source Station: ")
destination = input("Enter Destination Station: ")
departure_day = input("Enter Departure Day: ")
departure_time = input("Enter Departure Time (HH:MM:SS): ")
first_class_seats = int(input("Enter First Class Seats: "))
second_class_seats = int(input("Enter Second Class Seats: "))
sleeper_seats = int(input("Enter Sleeper Seats: "))
ticket_price = int(input("Enter Ticket Price: "))
cur.execute("""
INSERT INTO trains
(train_name, source, destination, departure_day, departure_time,
first_class_seats, second_class_seats, sleeper_seats, ticket_price)
VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", (train_name, source, destination, departure_day, departure_time,
first_class_seats, second_class_seats, sleeper_seats, ticket_price))
con.commit()
8
print("Train added successfully!")
print("-----------------------------")
def remove_train():
train_id = int(input("Enter Train ID to remove: "))
cur.execute(f"DELETE FROM trains WHERE train_id = {train_id}")
con.commit()
print("Train removed successfully!")
print("-----------------------------")
def display_trains():
print("Available Trains:")
cur.execute("SELECT * FROM trains")
rows = cur.fetchall()
for row in rows:
print("Train ID:", row[0])
print("Train Name:", row[1])
print("Source:", row[2])
print("Destination:", row[3])
print("Departure Day:", row[4])
print("Departure Time:", row[5])
print("First Class Seats:", row[6])
print("Second Class Seats:", row[7])
print("Sleeper Seats:", row[8])
print("Ticket Price:", row[9])
print("-----------------------------")
9
def book_train():
display_trains()
train_id = int(input("Enter the Train ID to book: "))
user_name = input("Enter your name: ")
seat_type = input("Enter the type of seat (first_class, second_class, sleeper):
").lower()
seats_booked = int(input("Enter the number of seats to book: "))
if result:
seat_capacity, ticket_price = result
rate = 1
if seat_type == 'second_class':
rate = 0.8
elif seat_type == 'sleeper':
rate = 0.6
10
INSERT INTO reservations (train_id, user_name, seats_booked,
total_price)
VALUES (%s, %s, %s, %s)
""", (train_id, user_name, seats_booked, total_price))
con.commit()
print("Booking successful!")
print("Reservation ID:", reservation_id)
print("Total Price: $", total_price)
print("Selected Seat Type:", seat_type)
print("-----------------------------")
else:
print("Not enough seats available.")
else:
print("Train not found.")
def cancel_train():
reservation_id = int(input("Enter the Reservation ID to cancel: "))
cur.execute(f"SELECT * FROM reservations WHERE reservation_id =
{reservation_id}")
reservation = cur.fetchone()
if reservation:
11
cur.execute(f"DELETE FROM reservations WHERE reservation_id =
{reservation_id}")
con.commit()
print("Booking canceled successfully!")
print("Refund Amount: $", reservation[4])
print("-----------------------------")
else:
print("Reservation not found.")
def view_trains():
print("\nTrain List:")
print("1. View All Trains")
print("2. View Trains with Different Pricing")
view_choice = input("Enter your choice: ")
if view_choice == '1':
display_trains()
elif view_choice == '2':
display_trains_with_pricing()
else:
print("Invalid choice. Returning to Admin Menu.")
def display_trains_with_pricing():
print("\nTrains with Different Pricing:")
cur.execute("SELECT * FROM trains")
rows = cur.fetchall()
for row in rows:
12
print("Train ID:", row[0])
print("Train Name:", row[1])
print("Source:", row[2])
print("Destination:", row[3])
print("Departure Day:", row[4])
print("Departure Time:", row[5])
print("First Class Seats:", row[6], "Price:", row[9])
print("Second Class Seats:", row[7], "Price:", row[9] * 0.8) # 80% of ticket
price for second class seats
print("Sleeper Seats:", row[8], "Price:", row[9] * 0.6) # 60% of ticket price
for sleeper seats
print("-----------------------------")
def admin_menu():
while True:
print("\nAdmin Menu:")
print("1. Add Train")
print("2. Remove Train")
print("3. View Trains")
print("4. Exit")
admin_choice = input("Enter your choice: ")
if admin_choice == '1':
add_train()
elif admin_choice == '2':
remove_train()
elif admin_choice == '3':
13
view_trains()
elif admin_choice == '4':
break
else:
print("Invalid choice. Please try again.")
def user_menu():
while True:
print("\nUser Menu:")
print("1. Display Available Trains")
print("2. Book a Train")
print("3. Cancel a Train")
print("4. Exit")
user_choice = input("Enter your choice: ")
if user_choice == '1':
display_trains()
elif user_choice == '2':
book_train()
elif user_choice == '3':
cancel_train()
elif user_choice == '4':
break
else:
print("Invalid choice. Please try again.")
14
# Database Connection
con = mysql.connector.connect(host='localhost', user='root', password='!
q@W#e123321')
cur = con.cursor()
cur.execute("""
CREATE TABLE IF NOT EXISTS reservations (
reservation_id INT AUTO_INCREMENT PRIMARY KEY,
train_id INT,
user_name VARCHAR(255) NOT NULL,
seats_booked INT NOT NULL,
total_price INT NOT NULL,
FOREIGN KEY (train_id) REFERENCES trains(train_id)
)
""")
con.commit()
# Main Menu
while True:
print("\nWelcome to Railway Reservation System")
16
print("1. Admin Login")
print("2. User Menu")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1':
if admin_login():
admin_menu()
else:
print("Invalid admin password!")
elif choice == '2':
user_menu()
elif choice == '3':
break
else:
print("Invalid choice. Please try again.")
17
Output Screenshots
18
19
20
21
Bibliography
1. python.org
2. Code Academy
3. tutorialsPoint.com
4. PythonChallenge.com
5. LearnPython.org
22