MS.
POORVA DWIVEDI
KUNWAR PRANJAL SINGH
KUNWAR PRANJAL SINGH
BUS RESERVATION SYSTEM
ACKNOWLEDGMENT
It is with pleasure that I acknowledge my sincere
gratitude to our teacher, MS. POORVA DWIVEDI
who taught and undertook the responsibility of
teaching the subject computer science. I have been
greatly benefited from his classes.
I am especially indebted to our Principal MS.
SURABHI SHARMA who has always been a source of
encouragement and support and without whose
inspiration this project would not have been a
successful I would like to place on record heartfelt
thanks to him.
Finally, I would like to express my sincere
appreciation for all the other students in my batch
their friend & the fine time that we all shared together.
PREFACE
The rapid growth of urbanization has led to an
increasing demand for efficient and accessible public
transportation systems. A key aspect of modern
transportation services is the ability to book seats in
advance, which ensures convenience for passengers
and better management for transport providers. This
project aims to develop a Bus Reservation System,
designed to streamline the process of booking and
managing bus tickets, providing an easy and efficient
method for both passengers and administrators.
The system will enable users to search for available
buses based on routes, dates, and seat preferences,
facilitating a seamless booking experience.
Additionally, it will offer administrative features to
manage bus schedules, reservations, and passenger
details, ensuring smooth operation.
This project is developed using MYSQL AND
PYTHON, with a focus on enhancing user experience
and operational efficiency. The goal is to create a
practical tool that can be extended and adapted to suit
the needs of real-world bus services.
DATABASE DESIGN
#CODE
import random
from tabulate import tabulate
import mysql.connector as con
# Establishing database connection
def connect_to_database():
try:
return con.connect(host="localhost", user="root", password="admin",
database="bus_reservation")
except con.Error as e:
print("Error connecting to database:", e)
exit()
dbo = connect_to_database()
co = dbo.cursor()
# NEW USER REGISTRATION SECTION
def new_user():
pid = random.randint(0, 1000) * 10
print("-" * 70)
print("\nWelcome to the Bus Reservation System\nRegister Yourself to Use the System")
uid = input("Enter your user ID: ")
name = input("Enter your name: ")
pno = input("Enter your phone number: ")
eid = input("Enter your email ID: ")
pwd = input("Enter your password: ")
co.execute("INSERT INTO user VALUES ('{}', {}, '{}', {}, '{}', '{}')".format(uid, pid, name,
pno, eid, pwd))
print("********* Registration Successful! *********")
print("-" * 70)
dbo.commit()
# FORGOT USER ID
def forgot_user_id():
email = input("Enter your registered email: ")
co.execute("SELECT user_id FROM user WHERE email_id = '{}'".format(email))
emel = co.fetchall()
for i in emel:
print("Your user ID is: ", i[0])
# OLD USER LOGIN
def old_user():
print("-" * 70)
uid = input("Enter your user ID: ")
co.execute("SELECT user_id FROM user WHERE user_id = '{}'".format(uid))
if co.fetchone() is None:
print("ID not registered. Choose an option:")
print("1. Try again\n2. Forgot user ID\n3. Register as a new user")
choice = int(input("Your choice: "))
if choice == 1:
old_user()
elif choice == 2:
forgot_user_id()
elif choice == 3:
new_user()
else:
pas = input("Enter your password: ")
co.execute("SELECT password FROM user WHERE user_id = '{}'".format(uid))
if pas == co.fetchone()[0]:
print("Welcome back! Accessing Passenger Panel.")
passenger_panel(uid)
# ADMIN PANEL PASSWORD
def admin_password():
password = input("Enter admin password: ")
if password == "ADMIN123":
print("Access Granted.")
admin_panel()
else:
print("Incorrect password. Try again.")
admin_password()
# ADD BUS
def add_bus():
print("-" * 70)
bus_no = int(input("Enter bus number: "))
name = input("Enter bus name: ")
origin = input("Enter origin: ")
destination = input("Enter destination: ")
journey_time = input("Enter journey time: ")
seats = int(input("Enter total seats: "))
fare = int(input("Enter fare: "))
co.execute("INSERT INTO bus_schedule VALUES ({}, '{}', '{}', '{}', '{}', {},
{})".format(bus_no, name, origin, destination, journey_time, seats, fare))
print("Bus added successfully!")
dbo.commit()
# SEARCH BUS
def search_bus():
origin = input("Enter origin: ")
destination = input("Enter destination: ")
co.execute("SELECT * FROM bus_schedule WHERE origin = '{}' AND destination =
'{}'".format(origin, destination))
buses = co.fetchall()
for bus in buses:
print(f"Bus No: {bus[0]}, Name: {bus[1]}, Seats: {bus[5]}, Fare: {bus[6]}")
# BOOK TICKETS
def book_ticket(uid):
search_bus()
bus_no = int(input("Enter the bus number you want to book: "))
seats = int(input("Enter number of seats: "))
co.execute("SELECT fare FROM bus_schedule WHERE bus_no = {}".format(bus_no))
fare = co.fetchone()[0]
total_cost = seats * fare
print(f"Total cost: {total_cost}")
for _ in range(seats):
name = input("Enter passenger name: ")
age = int(input("Enter passenger age: "))
co.execute("INSERT INTO booked_tickets (user_id, bus_no, name, age, status) VALUES
('{}', {}, '{}', {}, 'CONFIRMED')".format(uid, bus_no, name, age))
print("Booking confirmed!")
dbo.commit()
# CANCEL TICKET
def cancel_ticket():
ticket_id = int(input("Enter your ticket ID to cancel: "))
co.execute("DELETE FROM booked_tickets WHERE ticket_id = {}".format(ticket_id))
print("Ticket cancelled successfully!")
dbo.commit()
# PASSENGER PANEL
def passenger_panel(uid):
while True:
print("1. Search Bus\n2. Book Ticket\n3. Cancel Ticket\n4. Logout")
choice = int(input("Enter your choice: "))
if choice == 1:
search_bus()
elif choice == 2:
book_ticket(uid)
elif choice == 3:
cancel_ticket()
elif choice == 4:
print("Logging out.")
break
# ADMIN PANEL
def admin_panel():
while True:
print("1. Add Bus\n2. Logout")
choice = int(input("Enter your choice: "))
if choice == 1:
add_bus()
elif choice == 2:
print("Logging out.")
break
# MAIN MENU
def main_menu():
try:
while True:
print("1. Admin Panel\n2. Passenger Panel\n3. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
admin_password()
elif choice == 2:
new_user()
elif choice == 3:
print("Thank you for using the Bus Reservation System!")
break
except Exception as e:
print("An error occurred:", e)
exit()
# Entry point
if __name__ == "__main__":
main_menu()
OUTPUTS
1.Bus Reservation Main Page
********WELCOME TO BUS RESERVATION SYSTEM********
1. Admin Panel
2. Passenger Panel
3. Exit
Enter your choice:
2. Admin Login Panel
# for choice = 1 in main page
Enter admin password:
******************Access Granted********************
---------------------------------------------------------------------
******Welcome to admin panel******
1. Add Bus
2. Logout
Choose your option:
3. Add Bus
# for choice = 1 min admin panel
Enter bus number: 101
Enter bus name: Super Express
Enter origin: Delhi
Enter destination: Jaipur
Enter journey time: 4 hours
Enter total seats: 40
Enter fare: 500
Bus added successfully!
4. Passenger Panel
******Welcome to passenger panel****** # for choice= 2 in main page
1. Search Bus
2. Book Ticket
3. Cancel Ticket
4. Logout
Enter your choice to use:
5. Search Bus
# for choice = 1 in passenger panel
Enter the bus number you want to book: 101
Enter number of seats: 2
Total cost: 1000
Enter passenger name: John
Enter passenger age: 28
Enter passenger name: Alice
Enter passenger age: 26
Booking confirmed!
6. Booking Tickets
Enter the bus number you want to book: 101 # for choice = 2 in passenger panel
Enter number of seats: 2
Total cost: 1000
Enter passenger name: John
Enter passenger age: 28
Enter passenger name: Alice
Enter passenger age: 26
Booking confirmed!
7. Cancel Ticket
# for choice = 3 in passenger panel
Enter your ticket ID to cancel: 1001
*********** Your ticket cancelled Successfully ****************
BIBLIOGRAPHY
Information to complete this project file has been
taken from following sources: -
1. Computer Science with Python-
A Textbook for class 12th
By Sumita Arora
2. Class notes given by subject teacher.
3. A sample project made by subject teacher.