Editor

The Next Day

Advanced · Stretch · from Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

From the lesson: Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

Every day you make hundreds of decisions. If it's raining, you grab an umbrella. If the traffic light is red, you stop. If your phone battery is below 20%, you look for a charger. These are all conditional decisions - you check something and act based on the result.

Read the lesson

Write a function next_day(day, month, year) that returns the date of the following day as text in the form "YYYY-MM-DD".

next_day(14, 3, 2026)   # '2026-03-15'
next_day(30, 4, 2026)   # '2026-05-01'

The rules of the calendar:

  • April, June, September and November have 30 days. February has 28, or 29 in a leap year. Every other month has 31.
  • A year is a leap year when it divides by 4, except years that divide by 100, which are leap years only when they also divide by 400. So 2024 and 2000 are leap years, 1900 and 2026 are not.
  • Return the answer instead of printing it: Check calls next_day() with its own dates, some of them hidden.

    def next_day(day, month, year):
    pass
    Solution unlocks after your first Check

    What Check runs

    Your code runs first, then each of these lines, and 5 more that stay hidden. The output must match exactly.

    RunsExpected output
    next_day(14, 3, 2026)'2026-03-15'
    next_day(30, 4, 2026)'2026-05-01'

    More If-Else exercises

    All Python exercises · 50 practice problems · Control Flow quiz