Exercise 1 solution import calendar from datetime import date def add_months(d, n): year, month = divmod(d.year * 12 + d.month - 1 + n, 12) month += 1 day = min(d.day, calendar.monthrange(year, month)[1]) return date(year, month, day) start = date(2026, 1, 31) step = start print("n direct chained") for n in range(0, 5): direct = add_months(start, n) if n: step = add_months(step, 1) flag = "" if direct == step else " <-- differs" print(f"{n} {direct} {step}{flag}") Output (run, and exactly as shown): n direct chained 0 2026-01-31 2026-01-31 1 2026-02-28 2026-02-28 2 2026-03-31 2026-03-28 <-- differs 3 2026-04-30 2026-04-28 <-- differs 4 2026-05-31 2026-05-28 <-- differs Explanation: clamping loses information. Once 31 January has become 28 February, the original day number is gone, so adding one more month gives the 28th. Adding the whole number of months to the original date in one step keeps the 31 and clamps only at the end. Rule: always add from the original date, never from an already-clamped result.