──────────────────────────────────────

27. Equipment Checkout · Work Out When an Item Is Due

Parse an ISO date and calculate a due date using a duration.

Lesson files · lessons/models-and-state/dates-and-deadlines

Before you start
- Convert input text to a value before calculating with it.
- Check a calculation at a boundary.

By the end
- Parse a calendar date and calculate a due date seven days later.
- Predict and check the result when the due date crosses into a new year.

Where you can use it
Print the due date for a seven-day loan, even when the loan starts near the end of December.

A date represents a calendar day. timedelta represents a duration. date.fromisoformat can read a YYYY-MM-DD string. Adding a timedelta handles month and year boundaries. Use fixed dates in tests so results stay the same next week.

Predict
Why is the result in February?
- date arithmetic crosses the month boundary.
- timedelta always rounds up to a new month.

Worked example (example.py)

from datetime import date, timedelta
start = date.fromisoformat("2026-01-30")
print(start + timedelta(days=2))


Example result
2026-02-01

Read a loan date, add seven days, and print Due: followed by the ISO date.

Starter program (starter.py)

from datetime import date, timedelta
start = date.fromisoformat("2026-01-30")
print(start + timedelta(days=2))


Hint
Use date.fromisoformat(input()) and add timedelta(days=7).

Case 1. Try the sample
Input
2026-01-30
Expected output
Due: 2026-02-06

Case 2. Year boundary
Input
2026-12-29
Expected output
Due: 2027-01-05

Stretch
Try a leap-year input and explain the due day.

Reflect
What can go wrong if dates are treated as plain strings during arithmetic?

Check your prediction
date arithmetic crosses the month boundary. January ends after the 31st and adding two days to the 30th reaches 1 February.
