Thursday, 26 November 2026
PastThree rungs, one idea. Solving rung 1 counts. Climb as far as you can.
Days In A Month
if statements + calendar rules
How many days
Write a function called days_in
The month is a number from 1 (January) to 12 (December). Return how many days it has, and give February 28 days for now. April, June, September and November have 30, and all the others have 31.
Examples
| Input | Output |
|---|---|
| 1 | 31 |
| 2 | 28 |
| 4 | 30 |
| 12 | 31 |
There are extra hidden tests, so make it work in general, not just for these.
A leap year adds one
Write a function called days_if_leap
Now you are also told whether it is a leap year, as True or False. Return the number of days in the month. In a leap year February has 29 days, and nothing else changes.
Examples
| Input | Output |
|---|---|
| 2, True | 29 |
| 2, False | 28 |
| 4, True | 30 |
| 10, False | 31 |
There are extra hidden tests, so make it work in general, not just for these.
Work out the leap year
Write a function called month_days
Now you get the year instead. A year is a leap year when 4 goes into it exactly, except that years ending in 00 are only leap years when 400 goes into them. So 2024 and 2000 are leap years, but 2023 and 1900 are not. Return the number of days in the month of that year.
Examples
| Input | Output |
|---|---|
| 2, 2024 | 29 |
| 2, 2023 | 28 |
| 2, 1900 | 28 |
| 7, 2024 | 31 |
There are extra hidden tests, so make it work in general, not just for these.
Finish Rung 1 and today counts. Rungs 2 and 3 are there if you want to push further.