Dates and times · 9 / 15 Exercise Medium

Leap years and days in a month

Objective

Create a Python program that tells how many days a month has and whether the year is a leap year, using the calendar module.

Instructions

  • Read an integer n and then n lines with two integers year month (the month goes from 1 to 12).
  • Use calendar.monthrange(year, month) (the second value is the number of days) and calendar.isleap(year).
  • Show YYYY-MM: D days (leap year) or YYYY-MM: D days (non-leap year), with the month in two digits (for example 2024-02).
Input
3
2024 2
2026 2
2026 4
Output
2024-02: 29 days (leap year)
2026-02: 28 days (non-leap year)
2026-04: 30 days (non-leap year)

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise