Check if a Given Year is a Leap Year

Determine if a year is a leap year based on leap year rules.

Logic BuildingBeginner
Logic Building
# Take year as input
year = int(input("Enter a year: "))

# Check if leap year
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
    print("Leap year")
else:
    print("Not a leap year")

Output

Enter a year: 2024
Leap year

Enter a year: 2023
Not a leap year

Enter a year: 2000
Leap year

Leap year rules:

  1. Divisible by 4 AND not divisible by 100, OR
  2. Divisible by 400

Key Concepts:

  • Use or to combine two conditions
  • First condition: divisible by 4 but not by 100
  • Second condition: divisible by 400
  • Either condition makes it a leap year