Railway Management System Recently, our High School teacher gave us a pseudocode assignment for the preparation of CAIE's which was a Railway Management System. Everyone completed the task in pseudocode which for me was quite an inflexible program. So I tried my own code which is very much flexible than others. It took me a day to complete the code but there were some bugs and errors which took me almost another day to fix. Hence, can anyone comment on my code and my programming skills? And guide me with some improvements where necessary?
departure = ['09:00', '11:00', '13:00', '15:00'] # Timings of Train Departures
arrival = ['10:00', '12:00', '14:00', '16:00'] # Timings of Train Arrivals
depart_trains = 4
arrival_trains = 4
coaches = 6
total_seats = 80
total_passengers = [0]*len(departure)
ticket_price = 25

while departure:
    print(f&quot;&quot;&quot;{depart_trains} trains departing at: {departure}
{arrival_trains} trains arriving at: {arrival}
Price of Ticket/person: {ticket_price} dollars
Each Train has {coaches} coaches, each coach holding {total_seats} passengers :)
&quot;&quot;&quot;)
    commute = input(&quot;Enter Departure time: &quot;).strip()
    if commute in departure:
        index_train = departure.index(commute)
        print(f&quot;&quot;&quot;You chose Train departing at: {departure[index_train]}
&quot;&quot;&quot;)
        run = True
        while run:
            current_passengers = int(input(&quot;How many passengers are to sit: &quot;))
            if current_passengers &lt;= coaches*total_seats:
                total_passengers[index_train] += current_passengers
                if total_passengers[index_train] == coaches*total_seats:
                    departure.remove(departure[index_train])
                    arrival.remove(arrival[index_train])
                    total_passengers.pop(index_train)
                    depart_trains -= 1
                    arrival_trains -= 1
                    print(f&quot;&quot;&quot;Your total price is: {current_passengers*ticket_price} dollars 
&quot;&quot;&quot;)
                    run = False
                elif total_passengers[index_train] &lt; coaches*total_seats:
                    print(f&quot;&quot;&quot;Your total price is: {current_passengers*ticket_price} dollars
&quot;&quot;&quot;)
                    run = False
                elif total_passengers[index_train] &gt; coaches*total_seats:
                    total_passengers[index_train] -= current_passengers
                    print(f&quot;&quot;&quot;The Train departing at {departure[index_train]} has only {(coaches*total_seats)-total_passengers[index_train]} seats left :(
&quot;&quot;&quot;)
            else:
                print(f'''Only {coaches*total_seats} seats are available in Train departing at {departure[index_train]} :( 
''')
else:
    print(&quot;All Trains are reserved. Come Tomorrow :( &quot;)
There's nothing that looks bad at a first glance. Couple observations though:

It isn't clear what happens if the time entered isn't in the departure list. Consider adding a default case, even if just to explain to the user that he has to punch in a time present in the list.

A negative number of passengers is valid according to your program, but I doubt this is intentional. Always validate user input.

An exception is thrown if I enter a string instead of a number when asked for the passenger count. See above ;)

At first read, I thought total_seats was, well, the total number of seats but it is the number of seats per coach according to the script output. You might want to clarify that or rename the variable.

You can use \n in your prints to add newlines, I'm not a fan of binding the formatting of your code to the formatting of your output. Both of these lines print the same thing:


print(f&quot;&quot;&quot;Your total price is: {current_passengers*ticket_price} dollars 
&quot;&quot;&quot;)
print(f&quot;&quot;&quot;Your total price is: {current_passengers*ticket_price} dollars \n&quot;&quot;&quot;)


The run variable isn't as self-documenting as it could be if it was named incorrectInput or retryInput or something like that.

Take these two more as suggestions than actual issues with your code:

The fact that your timing system relies on list indexes isn't very pythonic (Explicit is better than implicit). You could use a dict to assign a unique ID to every train... But you'd need a bit more code to reproduce index_train = departure.index(commute), and I'm not a fan of doing syntax gymnastics in &quot;exam code&quot; so I'd say that your solution is good enough.
Another pythonic thing, &quot;Ask forgiveness not permission&quot;: you could get rid of the check for wether commut is in departure, do index_train = departure.index(commute) right away and handle the ValueError that gets thrown if commute isn't in departures using a try except block. Your solution is already fine though (and probably less verbose).

Overall I don't see anything that doesn't work as intended, so it's already pretty solid (as long as the user isn't messing with the input like I did). If it is &quot;exam code&quot; I'd prioritize the formatting and documentation stuff so that your code is more readable. Readable = fast to grade, and fast to grade = less time spend analyzing and figuring out every minor issue with the code ;)