Editor

Check for a Leap Year

Beginner · Write the code · from Python Booleans, Comparisons, and All Operators Explained

From the lesson: Python Booleans, Comparisons, and All Operators Explained

Every day you make yes-or-no decisions. "Is it raining?" "Do I have enough money?" "Is my password correct?" Computers make the same kind of decisions, and they use booleans to do it.

Read the lesson

Create a variable year set to 2024. A year is a leap year if:

  • It's divisible by 4
  • But not divisible by 100
  • Unless it's also divisible by 400
  • Use the modulo operator % and logical operators to check. Print the result.

    Expected output:

    True
    # Check if 2024 is a leap year

    More booleans and operators exercises

    All Python exercises · 50 practice problems · Python Fundamentals quiz