VIT Bhopal University
Course: Computer Science and Engineering
Submitted To: Professor Sasmita Padhy
Student Name: Chirag Bhatia
Registration Number: 25BAI10766
Date of Submission: November 23, 2025
The Train Booking System is a console-based application developed in Python that simulates a railway reservation management system. This project demonstrates fundamental concepts of data structures, object-oriented programming, and user-interactive applications. The system allows users to book train seats, view available and booked seats, cancel bookings, and print ticket details.
- Implement a practical railway seat management system using Python
- Demonstrate proficiency in object-oriented programming (OOP) concepts
- Utilize data structures such as lists and classes for efficient data storage
- Create an interactive menu-driven interface for user engagement
- Implement validation mechanisms to ensure data integrity
- Practice modular programming with well-defined functions
- Apply algorithmic thinking for business logic implementation
- Sets up 50 available seats in the train
- All seats are initially marked as unbooked
- Shows all unbooked seats in the train
- Helps passengers identify available seating options
- Allows passengers to reserve a seat
- Collects passenger information: name, age, source, and destination
- Validates seat availability before booking
- Provides confirmation upon successful booking
- Shows all reserved seats with passenger details
- Displays seat number, passenger name, age, and route information
- Provides a comprehensive view of current bookings
- Enables passengers to cancel their reservations
- Validates seat status before cancellation
- Provides confirmation upon successful cancellation
- Generates ticket details for a booked seat
- Displays passenger information and journey route
- Validates seat booking status before printing
| Component | Details |
|---|---|
| Programming Language | Python 3.x |
| Data Structure | Classes, Lists |
| Programming Paradigm | Object-Oriented Programming (OOP) |
| User Interface | Console-Based Menu System |
| Total Seats | 50 |
| Maximum Name Length | 50 characters |
Booking Class:
Attributes:
- name: str (Passenger's full name)
- age: int (Passenger's age)
- source: str (Journey starting point)
- destination: str (Journey ending point)
- seatnumber: int (Assigned seat number)
- isbooked: bool (Booking status - True if booked, False if available)
- train[]: A list containing 50 Booking objects representing each seat in the train
- Python 3.x installed on your system
- Basic familiarity with command-line interface
-
Navigate to the project directory in terminal/command prompt
cd path/to/project -
Run the Python script
python train-ticket-system.py
-
Follow the on-screen menu to perform desired operations:
- Enter
1to view available seats - Enter
2to book a seat - Enter
3to view booked seats - Enter
4to cancel a booking - Enter
5to print a ticket - Enter
6to exit
- Enter
The main menu presents all available operations with a clear, numbered choice system.
Shows the core Python implementation including class definition and function declarations.
Demonstrates the system's output format and user interaction flow.
ALGORITHM initializeSeats()
FOR j = 0 TO maxseats - 1 DO
train[j].isbooked ← FALSE
END FOR
END ALGORITHM
ALGORITHM displayAvailableSeats()
PRINT "Available Seats:"
FOR z = 0 TO maxseats - 1 DO
IF train[z].isbooked == FALSE THEN
PRINT "Seat ", z + 1
END IF
END FOR
END ALGORITHM
ALGORITHM bookSeat()
INPUT seatnumber
seatnumber ← seatnumber - 1 // Adjust for 0-based indexing
IF seatnumber < 0 OR seatnumber >= maxseats THEN
PRINT "Invalid Seat Number"
RETURN
END IF
IF train[seatnumber].isbooked == TRUE THEN
PRINT "Seat is Already Booked"
ELSE
train[seatnumber].isbooked ← TRUE
train[seatnumber].seatnumber ← seatnumber + 1
INPUT train[seatnumber].name
INPUT train[seatnumber].age
INPUT train[seatnumber].source
INPUT train[seatnumber].destination
PRINT "Seat Booked Successfully!"
END IF
END ALGORITHM
ALGORITHM displayBookedSeats()
PRINT "--- Booked Seats & Passengers ---"
booked_count ← 0
FOR i = 0 TO maxseats - 1 DO
IF train[i].isbooked == TRUE THEN
PRINT Seat Details: Seat Number, Name, Age, Route
booked_count ← booked_count + 1
END IF
END FOR
IF booked_count == 0 THEN
PRINT "No seats are currently booked."
END IF
PRINT "---------------------------------"
END ALGORITHM
ALGORITHM cancelSeat()
INPUT seatnumber
seatnumber ← seatnumber - 1 // Adjust for 0-based indexing
IF seatnumber < 0 OR seatnumber >= maxseats THEN
PRINT "Invalid Seat Number"
RETURN
END IF
IF train[seatnumber].isbooked == TRUE THEN
train[seatnumber].isbooked ← FALSE
PRINT "Seat Booking Cancelled Successfully"
ELSE
PRINT "Seat is not Booked"
END IF
END ALGORITHM
ALGORITHM printTicket(seatnumber)
seatnumber ← seatnumber - 1 // Adjust for 0-based indexing
IF seatnumber < 0 OR seatnumber >= maxseats THEN
PRINT "Invalid Seat Number"
RETURN
END IF
IF train[seatnumber].isbooked == TRUE THEN
PRINT "Ticket Details:"
PRINT train[seatnumber].name
PRINT train[seatnumber].age
PRINT train[seatnumber].source
PRINT train[seatnumber].destination
PRINT train[seatnumber].seatnumber
ELSE
PRINT "Seat is not Booked"
END IF
END ALGORITHM
ALGORITHM main()
initializeSeats()
choice ← 0
WHILE choice ≠ 6 DO
PRINT Main Menu Options
INPUT choice
SWITCH choice
CASE 1:
displayAvailableSeats()
CASE 2:
bookSeat()
CASE 3:
displayBookedSeats()
CASE 4:
cancelSeat()
CASE 5:
INPUT seatnumber
printTicket(seatnumber)
CASE 6:
PRINT "Exiting..."
DEFAULT:
PRINT "Invalid Choice"
END SWITCH
END WHILE
END ALGORITHM
START
↓
Initialize Train Seats (all seats marked as available)
↓
Display Main Menu
↓
User Makes Selection
├─→ Option 1: View Available Seats → Display List → Return to Menu
├─→ Option 2: Book Seat → Input Details → Validate → Confirm → Return to Menu
├─→ Option 3: View Booked Seats → Display List → Return to Menu
├─→ Option 4: Cancel Booking → Input Seat → Validate → Confirm → Return to Menu
├─→ Option 5: Print Ticket → Input Seat Number → Validate → Display Details → Return to Menu
└─→ Option 6: Exit → END
↓
Loop Until User Chooses Exit
┌─────────────────────┐
│ START │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Initialize Seats │
│ (All = Available) │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Display Menu │
└──────────┬──────────┘
│
┌──────────────────┼──────────────────┐
│ │ │
┌────▼─────┐ ┌─────▼────┐ ┌─────▼────┐
│ Option 1 │ │ Option 2 │ │ Option 3 │
│ Display │ │ Book │ │ Display │
│ Available │ │ Seat │ │ Booked │
│ Seats │ │ │ │ Seats │
└────┬─────┘ └─────┬────┘ └─────┬────┘
│ │ │
┌────▼────┐ ┌────▼───────────┐ │
│Show List│ │Valid Input? │ │
└────┬────┘ └┬──────────┬────┘ │
│ │ │ │
│ Y N │
│ │ │ │
┌────▼──────┐ ┌────▼────┐ ┌──▼────┐ │
│Return Menu│ │Book Seat│ │Error │ │
└───────────┘ └────┬────┘ └───┬───┘ │
│ │ │
┌────▼──────┐ │ │
│Collect │ │ │
│Details │ │ │
└────┬──────┘ │ │
│ │ │
┌────▼──────┬───▼───┐ │
│Confirm & │Return │ │
│Update │Menu │ │
└────┬──────┴───┬───┘ │
│ │ │
┌────▼──────────▼───┐ │
│ Return to Menu │◄──┘
└────┬──────────────┘
│
┌───────────┼───────────┐
│ │ │
┌───▼───┐ ┌───▼───┐ ┌───▼───┐
│Option │ │Option │ │Option │
│ 4, 5 │ │ 6 │ │ 1-5 │
│Cancel/│ │ Exit │ │Repeat │
│Print │ │ │ │ │
└───┬───┘ └───┬───┘ └───┬───┘
│ │ │
┌───▼───────────▼──────────▼───┐
│ Return to Menu / Continue │
└───┬──────────────────────────┘
│
┌──────────┐ │
│ │ │
└──────────┘ │
│
┌───────▼────────┐
│ Process Exit │
│ or Loop │
└───────┬────────┘
│
┌───────▼────────┐
│ END │
└────────────────┘
- Encapsulates all information for a single train seat reservation
- Implements OOP principles through data encapsulation
train[]stores 50 Booking instances- Each index represents a physical seat in the train
- Provides O(1) access time for seat information
| Function | Purpose | Parameters | Return Type |
|---|---|---|---|
initializeSeats() |
Initialize all seats as available | None | None |
displayAvailableSeats() |
Show all vacant seats | None | None |
displayBookedSeats() |
Show all reserved seats with details | None | None |
bookSeat() |
Reserve a seat with passenger info | None | None |
cancelSeat() |
Cancel an existing booking | None | None |
printTicket(seatnumber) |
Display ticket for booked seat | int | None |
main() |
Main application loop | None | None |
User Input
↓
Input Validation
↓
Data Processing
↓
Database Operation (List Update)
↓
Status Confirmation
↓
Display Result
↓
Return to Main Menu
The system implements robust error handling for:
- Invalid Seat Numbers: Out of range seat selections are rejected
- Duplicate Bookings: Prevents booking of already reserved seats
- Cancellation of Empty Seats: Notifies user if trying to cancel non-existent booking
- Invalid Menu Choices: Prompts user to select valid options
- Input Validation: Ensures valid seat number range (1-50)
- Simple and Intuitive: Easy to understand for users and developers
- Efficient Data Access: List-based storage provides O(1) lookup time
- Scalable: Can easily expand to support more seats by changing
maxseatsconstant - Modular Design: Each function performs a specific task independently
- Interactive Interface: User-friendly menu-driven console application
- No Persistence: Data is lost when application terminates
- Single Train: System manages only one train
- Limited Fields: Basic passenger information only
- No Database Integration: Uses in-memory storage only
- Add file-based persistence using CSV or JSON
- Implement database integration with SQLite or MySQL
- Add multiple train support with different routes
- Include payment processing and booking confirmation
- Add user authentication and booking history
- Implement email notifications for bookings
- Add date-based scheduling for different travel dates
- Include pricing tiers based on seat category
- Add search functionality for routes and timings
- Implement cancellation policies and refund calculation
-
Seat Availability Display
- Verify all 50 seats are initially displayed as available
-
Booking Functionality
- Book a valid seat and verify status change
- Attempt to book an already booked seat (should fail)
- Test boundary conditions (Seat 1 and Seat 50)
-
Cancellation
- Cancel a booked seat and verify availability
- Attempt to cancel an unbooked seat (should fail)
-
Ticket Printing
- Print ticket for booked seat and verify details
- Attempt to print ticket for unbooked seat (should fail)
-
Input Validation
- Test with invalid seat numbers (negative, > 50, non-numeric)
- Test with empty passenger names
- Test with invalid age values
The Train Booking System project successfully demonstrates core concepts of Python programming including object-oriented design, data structure utilization, and interactive application development. This system serves as a foundation for understanding real-world ticketing systems and can be extended with additional features for practical deployment.
- Python Official Documentation: https://docs.python.org/3/
- Object-Oriented Programming Principles
- Data Structures and Algorithms Fundamentals
- Software Engineering Best Practices
Project Submitted: November 23, 2025
Academic Year: 2025-2026
Semester: Fall