Untitled
unknown
python
a year ago
3.8 kB
7
Indexable
import os
# Yik Yang
def viewTrainSchedules(trains):
# draw the view train schedules out
while (True):
print(" Available Train ")
print("_________________________\n\n")
print(f"| {"Train No":<12} | {"Name":<15} | {"Origin":<15} | {"Destination":<15} | {"Available Seat":<20} | {"Fare":<10} | {"Departure":<12} | {"Arrival":<12} |")
print("----------------------------------------------------------------------------------------------------------------------------------------")
for train in trains:
print(f"| {train["Train No"]:<12} | {train["Name"]:<15} | {train["Origin"]:<15} | {train["Destination"]:<15} | {train["Available Seat"]:<20} | {train["Fare"]:<10} | {train["Departure"]:<12} | {train["Arrival"]:<12} |")
break
input("\nPress any key to Main Menu >> ")
os.system("cls")
# Li Hen
def bookTickets(trains, bookings):
while (True):
print("Implement your book tickets here")
print("Implement your book tickets here")
for train in trains:
print(f"{train['Train No']} - {train['Name']} (Fare: {train['Fare']}, Available Seats: {train['Available Seat']})")
input("\nPress any key to Main Menu >> ")
os.system("cls")
# Malcolm
def viewBookings():
print("Implement your view bookings here")
# QinYi
def cancelTickets():
print("Implement your cancel tickets here")
# main entry point of the program
def main():
while (True):
# declare variables here
trains = [
{"Train No": "101", "Name": "Express A", "Origin": "City A", "Destination": "City D", "Available Seat": 48, "Fare": 50, "Departure": "08.00", "Arrival": "11.00"},
{"Train No": "102", "Name": "Express B", "Origin": "City B", "Destination": "City E", "Available Seat": 48, "Fare": 100, "Departure": "22.00", "Arrival": "23.00"},
{"Train No": "103", "Name": "Express C", "Origin": "City C", "Destination": "City F", "Available Seat": 48, "Fare": 200, "Departure": "18.00", "Arrival": "20.00"},
]
booking = {
"Train No": trains["Train No"],
"Name": trains["Name"],
"Fare": trains["Fare"]
}
bookings.append(booking)
# draw the main menu
print(" Train Ticket System ")
print("____________________________")
print("| (1) View Train Schedules |")
print("----------------------------")
print("| (2) Book Tickets |")
print("----------------------------")
print("| (3) View Bookings |")
print("----------------------------")
print("| (4) Cancel Tickets |")
print("----------------------------")
print("| (5) Exit Program |")
print("----------------------------")
choice = input("\nEnter your choice >> ")
if choice == "1":
os.system("cls")
viewTrainSchedules(trains)
continue
elif choice == "2":
os.system("cls")
bookTickets(bookings)
continue
elif choice == "3":
os.system("cls")
viewBookings()
continue
elif choice == "4":
os.system("cls")
cancelTickets()
continue
elif choice == "5":
os.system("cls")
print("Thanks for using our service, bye!")
break
else:
input("Invalid input! (Press any key to try again) >>")
os.system("cls")
continue
# call the main() function
main()Editor is loading...
Leave a Comment