#540 · Python Basics · Beginner · 30 XP · about 5 min
Write days_in_month(month, year) that returns how many days a month has. month is a number from 1 (January) to 12 (December).
A year is a leap year when it is divisible by 4, except a year divisible by 100, which is not, unless it is also divisible by 400.
days_in_month(1, 2023) # returns 31 days_in_month(4, 2023) # returns 30 days_in_month(2, 2024) # returns 29 days_in_month(2, 1900) # returns 28
1900 is divisible by 100 but not by 400, so its February had 28 days.
First solves only, ranked by stars and then time.