Problem 186935 · easy · Phase 01 Prerequisites & Setup

Leap Year

booleans · boolean logic · modulo

A leap year has 366 days instead of 365. The rule is:

  • A year is a leap year if it is divisible by 4,
  • except that years divisible by 100 are not leap years,
  • except that years divisible by 400 are leap years after all.

So 2024 is a leap year (divisible by 4), 1900 is not (divisible by 100 but not 400), and 2000 is (divisible by 400).

Write a function is_leap_year(year) that returns True if year is a leap year and False otherwise.

Examples

Input:  year = 2024
Output: True
Input:  year = 1900
Output: False
Explanation: 1900 is divisible by 100 but not by 400.
Input:  year = 2000
Output: True
Explanation: 2000 is divisible by 400.

Constraints

  • 1 <= year <= 9999
  • Return a real boolean (True/False), not the strings "True"/"False".

Goals

  • Return True or False directly from a function
  • Combine conditions with and, or and not
  • Test divisibility with the % operator
Starting Python…