Editor

When Is the Book Due?

#575 · Modules and random · Beginner · 35 XP · about 6 min

A school library lends books for a number of days. Write due_date(borrowed, days) where borrowed is the date a book was taken out, written 'YYYY-MM-DD', and days is the length of the loan:

  • Add days days to the date.
  • The library is closed on Sundays, so a book that would be due on a Sunday is due on the Monday after instead.
  • Return the weekday's name, a space and the date, such as 'Monday 2026-11-16'.

The datetime module does the calendar work: date.fromisoformat reads the date, adding a timedelta(days=...) moves it on, weekday() gives 0 for Monday up to 6 for Sunday, and strftime('%A') gives the weekday's name.

Examples

due_date('2026-11-02', 14)  # returns 'Monday 2026-11-16'
due_date('2026-11-02', 13)  # returns 'Monday 2026-11-16'
due_date('2026-11-07', 7)   # returns 'Saturday 2026-11-14'

With 13 days the book would be due on Sunday 15 November, so it moves to the Monday.

Constraints

  • 1 <= days <= 1000

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.