Untitled Document
Untitled Document
PROJECT
SESSION: 2024-2025
Project Topic: Booking Train Tickets System
Name:
Class:
Roll No:
Certificate
_________ _________
Signature of signature of
Internal examiner external examiner
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude
to my respected principal ma’am
Dr Eshwari Prabhakar
and also to my computer science teacher
____________________
Who have gave me the golden opportunity
to do this wonderful project on
‘TRAIN TICKET BOOKING SYSTEM’
And who has also helped me in completing my
project. I came to know about so many new things, I
am really thankful to them.
Secondly , I would also like to thank my parents and
friends who have helped me a lot in finalizing this
project within the limited time frame.
INDEX
1.Certificate
2. Acknowledgement
3. Hardware and Software
4. Introduction
5. Objective of the project
6. Core Functionalities
7. Significance of the project
8. SQLite Databases
9. Python Source Code
10.Output
11.Bibliography
HARDWARE AND
SOFTWARE REQUIRED
HARDWARE
1. Desktop computer/laptop
2. Mobile Phone
SOFTWARE
1. Python
2. SQLite
3. Python connector module
INTRODUCTION
A train ticket booking system lets passengers easily
book tickets online, select routes, dates, and seats,
and pay securely. It offers features like instant
confirmation, e-tickets, and booking modifications.
With multiple payment options and real-time
updates, it enhances convenience for travelers and
improves efficiency for railway operators.
2. insert_sample_data():
3. view_trains():
5. view_bookings(user_id):
1. SQLite
Serves as the backend database, ensuring secure
and structured data storage.
2. Python
Acts as the interface for the system.
Features user-friendly, menu driven
programming to simplify navigation and
execution.
SIGNIFICANCE OF THE PROJECT
1. Database Integration: Demonstrates how to use SQLite
with Python to manage and store data in a database, a crucial
skill for building data-driven applications.
2.CRUD Operations: Covers basic Create, Read, Update,
Delete (CRUD) operations, which are essential for
managing data in real-world applications.
3.Real-World Application: Provides a simple example of a
ticket booking system, simulating a real-world scenario that
can be expanded into more complex systems.
4.User Interaction: Teaches how to interact with users,
retrieve data, and update it based on user input—core
functionality in most software.
5.Data Integrity: Ensures that operations like seat booking
are handled correctly by checking available seats and
preventing overbooking.
6.Scalability: Offers a basic structure that can be easily
extended with additional features like payment processing,
user authentication, and more.
7. Python & SQLite Skills: Provides hands-on experience
with Python and SQLite, widely used technologies in
software development for creating database-backed
applications.
import sqlite3
def create_db():
# Connect to SQLite database (or create it if
it doesn't exist)
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
phone TEXT NOT NULL
);
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS bookings
(
booking_id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
train_id INTEGER NOT NULL,
seat_number INTEGER NOT NULL,
booking_time TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES
users(user_id),
FOREIGN KEY (train_id) REFERENCES
trains(train_id)
);
''')
conn.commit()
conn.close()
conn.commit()
conn.close()
import sqlite3
from datetime import datetime
def view_trains():
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()
print("\nAvailable Trains:")
print("-" * 50)
for train in trains:
print(f"ID: {train[0]}, Name: {train[1]},
From: {train[2]} To: {train[3]}, Departure:
{train[4]}, Seats Available: {train[5]}")
conn.close()
if train:
available_seats = train[0]
if available_seats >= num_seats:
# Reduce available seats
cursor.execute('UPDATE trains SET
available_seats = available_seats - ? WHERE
train_id = ?', (num_seats, train_id))
conn.commit()
print(f"\nBooking successful! Your seat
number is {seat_number}.")
else:
print(f"\nNot enough available seats.
Only {available_seats} seats are available.")
else:
print("\nTrain not found.")
conn.close()
def view_bookings(user_id):
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()
cursor.execute('''
SELECT b.booking_id, t.name, t.origin,
t.destination, t.departure_time,
b.seat_number, b.booking_time
FROM bookings b
JOIN trains t ON b.train_id = t.train_id
WHERE b.user_id = ?
''', (user_id,))
bookings = cursor.fetchall()
if bookings:
print("\nYour Bookings:")
print("-" * 50)
for booking in bookings:
print(f"Booking ID: {booking[0]},
Train: {booking[1]}, From: {booking[2]} To:
{booking[3]}, Departure: {booking[4]}, Seat
Number: {booking[5]}, Booking Time:
{booking[6]}")
else:
print("\nYou have no bookings.")
conn.close()
# Test the system
if __name__ == '__main__':
# Let's assume the user has a user_id of 1
for simplicity.
user_id = 1
Your Bookings:
--------------------------------------------------
Booking ID: 1, Train: Express 101, From: New York To:
Los Angeles, Departure: 2025-01-20 08:00, Seat
Number: 1, Booking Time: 2025-01-18 10:45:32
BIBLIOGRAPHY