Dates and times · 8 / 15 Exercise Medium

Add days to a date

Objective

Create a Python program that adds (or subtracts) a number of days to a date using timedelta, and says which day of the week the result falls on.

Instructions

  • Read an integer n and then n lines with the format YYYY-MM-DD days (the number of days is an integer, negative to subtract).
  • Add timedelta(days=...) to the date and show Result: YYYY-MM-DD (day) with the capitalized day name (as in the previous exercise).
  • The module takes care of months of different lengths and leap years.
Input
3
2026-01-31 30
2026-03-01 -1
2026-12-31 1
Output
Result: 2026-03-02 (Monday)
Result: 2026-02-28 (Saturday)
Result: 2027-01-01 (Friday)

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

Start exercise