Indian Railways Announcement System in Python

Home » Coding » Indian Railways Announcement System in Python

The Indian Railways is one of the world’s largest railway networks, serving millions of passengers daily across various stations and trains. The Indian Railways Announcement System in Python is a simple implementation that mimics the announcement system used in the Indian Railways and plays a crucial role in keeping passengers informed about train departures, arrivals, delays, and other important information.

Introduction

The​ Indian Railways Announcement System in Python is an application that provides information on the arrival​ and departure of the train. The announcement is displayed after each interval of time that is mentioned. This project will use different functions for the train’s announcement, arrival, and departure.

Objective

The objective is to create a computerized system that can generate automated announcements​ for various events and situations related to the Indian Railways. This system aims to provide timely and accurate information​ to passengers and staff at railway stations.

Requirements

1. You must have a basic​ understanding of Python.

2. Any text editor or Visual Studio Code

3. To run and build the Python ​code on your machine, ​you will need a Python Environment.

Source Code

import time
def play_announcement(message):
print("Playing announcement:")
print(message)
# Add code here to play the announcement audio
def announce_train_departure(train_number, destination, departure_time):
message = f"Train {train_number} to {destination} is departing at {departure_time}. Please proceed to the platform."
play_announcement(message)
def announce_train_arrival(train_number, source, arrival_time):
message = f"Train {train_number} from {source} has arrived at {arrival_time}. Please wait for passengers to disembark."
play_announcement(message)
# Example usage:
train_1_number = "770890"
train_1_destination = "Chennai"
train_1_departure_time = "11:05 AM"
train_2_number = "842561"
train_2_source = "Agra"
train_2_arrival_time = "03:45 PM"
train_3_number = "758941"
train_3_source = "Bangalore"
train_3_arrival_time = "06:45 PM"
announce_train_departure(train_1_number, train_1_destination, train_1_departure_time)
time.sleep(5) # Wait for 5 seconds between announcements
announce_train_arrival(train_2_number, train_2_source, train_2_arrival_time)
time.sleep(5) # Wait for 5 seconds between announcements
announce_train_arrival(train_3_number, train_3_source, train_3_arrival_time)

Explanation of Code

1. In this project code,​ we defined a function called `play_announcement(message)`, which takes a message as input and prints it as an announcement.

2. We also defined two announcement​ functions: `announce_train_departure(train_number, destination, departure_time)` and `announce_train_arrival(train_number, source, arrival_time)`. ​These functions generate specific announcement messages for train departures and arrivals by formatting the provided​ information into a message string.

3. Then, we used the `announce_train_departure` function,​ which is called with the first train’s departure details, followed by the `announce_train_arrival` function calls for the remaining two trains.

4. Between each announcement, ​we gave an interval of `time.sleep(5)` statement, which pauses the program execution for 5 seconds. This is added to simulate a ​delay between consecutive announcements.

Output

Indian Railways Announcement System in Python

Figure 1: Announcement ​with time interval

Conclusion

Hence, we have successfully ​developed an Indian Railways Announcement System in Python. It generates timely announcements for train departures and arrivals, ​supports multilingualism, integrates with real-time data, and provides customization options. It enhances passenger experience​ and facilitates efficient railway operations.

More Python Projects>>>

 

You May Also Like To Create…