Skip to content
doubtly

1 answer

Best answer

Answer: A year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400.

year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
    print(year, "is a leap year")
else:
    print(year, "is not a leap year")

How it works

  • year % 4 == 0 and year % 100 != 0 catches ordinary leap years such as 2024.
  • year % 400 == 0 catches century leap years such as 2000.
  • Century years not divisible by 400, such as 1900, fail both tests, so they are not leap years.

Sample runs: 2024 → leap year, 2000 → leap year, 1900 → not a leap year, 2023 → not a leap year.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.