Python bootcamp · Lab 25

Leap year

easyIf Else10 minLesson: If Else

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read a year and print yes if it is a leap year, otherwise no.

A year is a leap year if it is divisible by 4, except centuries (divisible by 100) which must also be divisible by 400.

Input. One line: an integer year.

Output. yes or no (lowercase).

Constraints

  • 1 ≤ year ≤ 9999

Examples

Example 1 — A century divisible by 400.
Input
2000
Output
yes
Example 2 — A century not divisible by 400.
Input
1900
Output
no
Example 3
Input
2024
Output
yes
Hint
  1. year % 400 == 0 is always a leap year.
  2. Otherwise year % 4 == 0 and year % 100 != 0.
Show correct code

Peek only after you have tried. You can still Check your own version.

year = int(input())
leap = year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)
print("yes" if leap else "no")
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.