Dates and times · 15 / 15 Exercise Hard

Event schedule

Objective

Create a Python program that sorts events by date and time and computes the time elapsed between the first and the last. datetime objects can be compared and sorted just like numbers.

Instructions

  • Read an integer n (at least 1) and then n lines with the format YYYY-MM-DD HH:MM name. The event name has no spaces.
  • Store each event as a tuple (datetime, name) and sort the list with sort().
  • Show the sorted events, one per line, with the format 15/03 09:30 - name (day/month and hour:minutes, with zeros).
  • At the end show Between the first and the last: Dd Hh Mm with the time between the first and the last event.
Input
3
2026-03-16 10:00 reunion
2026-03-15 09:30 desayuno
2026-03-15 21:00 cena
Output
15/03 09:30 - desayuno
15/03 21:00 - cena
16/03 10:00 - reunion
Between the first and the last: 1d 0h 30m

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise