All challenges

Thursday, 26 November 2026

Past

Three rungs, one idea. Solving rung 1 counts. Climb as far as you can.

Days In A Month

if statements + calendar rules

Rung 1Daily goal5 points

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

InputOutput
131
228
430
1231

There are extra hidden tests, so make it work in general, not just for these.

Rung 2Bonus7 points

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

InputOutput
2, True29
2, False28
4, True30
10, False31

There are extra hidden tests, so make it work in general, not just for these.

Rung 3Bonus10 points

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

InputOutput
2, 202429
2, 202328
2, 190028
7, 202431

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.