My program which is supposed to print the next available train time for the current date using the current time.
It should be printing the next available times from the 5 trains that are listed in the CSV file and it doesn’t.
def SetSchedules():
current_time = datetime.datetime.now().strftime("%H:%M")
today = datetime.date.today().strftime("%Y-%m-%d")
print(f"Current time: {current_time}")
print(f"Today's date: {today}")
available_trains = []
# Find the index for today's date
try:
today_index = Dates.index(today)
except ValueError:
print("Today's date is not found in the timetable.")
return
# Get the train times for today
train_times = [Train1[today_index], Train2[today_index], Train3[today_index], Train4[today_index],
Train5[today_index]]
# Check for the next available train times
for train_number, train_time in enumerate(train_times, start=1):
if train_time > current_time:
available_trains.append((train_number, train_time))
if available_trains:
print("Next available trains for today:")
for train_number, train_time in available_trains:
print(f"Train {train_number} at {train_time}")
else:
print("No available trains for today.")
It prints
Current time: 16:31
Today's date: 2024-05-31
Today's date is not found in the timetable.
31/05/2024 02:52 13:03 18:31 21:11 22:27
3