easy +8 pts

Days in month

Find how many days a month has, handle leap years like a pro.

Write a function `days_in_month(year: int, month: int) -> int` that returns the number of days in the given month (1–12) of the given year. Use the Gregorian calendar rules. - The function must accept an integer `year` (>= 1) and an integer `month` from 1 (January) to 12 (December). - It must return an integer representing the number of days in that month. - The Gregorian leap year rule: a year is a leap year if it is divisible by 4, except if it is divisible by 100 but not by 400. Do NOT use `calendar.monthrange`, `datetime`, or any external libraries.

Constraints

- `1 <= year <= 3000` - `1 <= month <= 12` - You may assume the input is always an integer within the given range. - The function should return an integer.

Example

>>> days_in_month(2023, 2)
28
>>> days_in_month(2024, 2)
29
>>> days_in_month(2000, 2)
29
>>> days_in_month(1900, 2)
28
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Create a list of days for each month, where February is 28 by default.
Handle the leap year for February: year % 4 == 0 and (year % 100 != 0 or year % 400 == 0).
Check the month boundary: if month is out of 1–12, what should happen? (The problem guarantees valid input, but you can still guard for safety.)
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.