Skip to content
Exercise · Operators · lesson 8 of 9

Exercise: leap year

Write a function is_leap(year) that returns True if the year is a leap year and False if it is not. A year is a leap year if one of these rules holds:

  • the year is divisible by 4 but not by 100;
  • the year is divisible by 400.
  • is_leap(2024) → True
  • is_leap(1900) → False
  • is_leap(2000) → True

Constraints: year is an integer from 1 to 9999. The tests check the answer with got is True or got is False: it demands exactly True or False, so the number 1 in place of True does not pass.

Do not add extra imports unless the task says so explicitly.

leap.py — python
python · 3 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way