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 != 0catches ordinary leap years such as 2024.year % 400 == 0catches 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.