KENDRIYA VIDYALYA NFC
VIGYAN VIHAR
SESSION 2022-23
COMPUTER SCIENCE PROJECT FILE
Naveen Yadav
XII E
Roll no: 32
CERTIFICATE
This is to certify that this practical file is
Submitted by Naveen Yadav under
my supervision in computer lab in session 2022-23
They have taken proper care and shown utmost
sincerity in completing this practical.
I certify that this practical file is up to my
expectations and as per the guidelines issued by
CBSE.
Shilpi Singh
Date:21/12/2022
ACKNOWLEDGEMET
I would like to express our sincere gratitude to my
computer science teacher Ms. Shilpi Singh for her vital
support, guidance and encouragement without which
this practical file would not come forth from my side,
she helped me completing the file by giving me ideas
thoughts and made this project easy and accurate. I
wish to thank my principal who inspired me to go my
own way without which I would be unable to complete
my file
Naveen Yadav
XII E
Roll no 32
INDEX
Introduction 1
Configuration 2
Python code 3
Out put 4
INTRODUCTION
Railway management
In this project I have used python to make a Railway
management system.
This code includes functions to display the schedules
and ticket availability for all trains, search for trains by
departure and arrival stations, purchase tickets, view
the ticket sales report, and cancel tickets
CONFIGURATION
Configuration of python
python 3.11
Python code
# Railway management system
# Constants
MAX_TRAINS = 100 # Maximum number of trains
MAX_TICKETS = 1000 # Maximum number of tickets per train
# Train class
class Train:
def __init__(self, train_id, name, source, destination, tickets_available):
self.train_id = train_id
self.name = name
self.source = source
self.destination = destination
self.tickets_available = tickets_available
def __str__(self):
return f"Train ID: {self.train_id}, Name: {self.name}, Source: {self.source}, Destination:
{self.destination}, Tickets available: {self.tickets_available}"
# Global list to store all trains
trains = []
# Function to display the schedules and ticket availability for all trains
def display_schedules():
if not trains:
print("No trains available.")
else:
for train in trains:
print(train)
# Function to search for trains by departure and arrival stations
def search_trains(source, destination):
found_trains = []
for train in trains:
if train.source == source and train.destination == destination:
found_trains.append(train)
return found_trains
# Function to purchase tickets
def purchase_tickets(train_id, num_tickets):
# Find the train
train = None
for t in trains:
if t.train_id == train_id:
train = t
break
# Check if the train was found
if not train:
print("Invalid train ID.")
return
# Check if the number of tickets requested is available
if train.tickets_available < num_tickets:
print("Not enough tickets available.")
return
# Purchase tickets
train.tickets_available -= num_tickets
print(f"{num_tickets} tickets purchased for train {train.name}.")
# Function to view the ticket sales report
def view_ticket_sales_report():
total_tickets_sold = 0
total_revenue = 0
for train in trains:
total_tickets_sold += (MAX_TICKETS - train.tickets_available)
total_revenue += ((MAX_TICKETS - train.tickets_available) * train.ticket_price)
print(f"Total tickets sold: {total_tickets_sold}, Total revenue: {total_revenue}")
# Function to cancel tickets
def cancel_tickets(train_id, num_tickets):
# Find the train
train = None
for t in trains:
if t.train_id == train_id:
train = t
break
# Check if the train was found
if not train:
print("Invalid train ID.")
return
# Cancel tickets
train.tickets_available += num_tickets
print(f"{num_tickets} tickets cancelled for train {train.name}")
OUTPUT OF THE CODE
the out put will depend upon the data inputs that the railway provides to this code, given
below is the out based on data I fed into the sy
Welcome to Sunset Railroad!
Train schedules:
Express: 7:00 AM, 9:00 AM, 11:00 AM, 1:00 PM, 3:00 PM
Local: 8:00 AM, 10:00 AM, 12:00 PM, 2:00 PM, 4:00 PM
Freight: 9:00 PM, 11:00 PM
TICKET AVAILABILITY
Train ID: 1, Name: Mumbai Express, Source: Mumbai, Destination: Delhi, Tickets available:
500
Train ID: 2, Name: Delhi Duronto, Source: Delhi, Destination: Chennai, Tickets available: 600
Train ID: 3, Name: Chennai Mail, Source: Chennai, Destination: Mumbai, Tickets available:
450
found_trains = search_trains("Delhi", "Chennai")
print(found_trains)
[Train ID: 2, Name: Delhi Duronto, Source: Delhi, Destination: Chennai, Tickets available:
600]
purchase_tickets(2, 100)
100 tickets purchased for train Delhi Duronto.
cancel_tickets(2, 50)
50 tickets cancelled for train Delhi Duronto
LIMITATIONS
1. The code does not handle cases where the train ID is invalid or does not exist. If an
invalid train ID is entered, the system will raise an exception.
2. The code does not handle cases where the number of tickets requested is more than the
maximum number of tickets available per train. This could lead to unexpected behavior
or errors.
3. The code does not handle cases where the number of tickets requested is negative or
zero. This could lead to unexpected behavior or errors.
4. The code does not handle cases where the source and destination stations are invalid or
do not exist. If an invalid station is entered, the system will raise an exception.
5. The code does not provide a way to add new trains or modify existing trains. The list of
trains is fixed and cannot be modified by the user.
CONCLUSION
This system has been made to reduce the manual work when managing train schedules,
availability of the tickets, Number of tickets sold and cancelled and it also allows the
Passengers to book the tickets and cancel them to some degree with some features missing
which are included in the limitations