A year is a leap year if it divides by 4, except years that divide by 100, which are leap years only if they also divide by 400. So 2024 is a leap year, 1900 is not, and 2000 is.
The program
python
year = int(input("Year: ")) if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print(f"{year} is a leap year") else: print(f"{year} is not a leap year")
Typed in this example: 1900. Press Run to type your own.
output
Year: 1900 1900 is not a leap year
How it works
year % 4 == 0means "divides by 4 with no remainder".!=means "is not equal to".- The brackets group the first rule: divisible by 4 and not by 100. The
oradds the exception: any year divisible by 400.
Checking several years
The standard library already has this rule, in the calendar module:
python
import calendar for year in [2023, 2024, 1900, 2000]: print(year, calendar.isleap(year))
output
2023 False 2024 True 1900 False 2000 True