Conditional Statements · Python example
Combine divisibility rules to decide whether a year is a leap year.
Leap years follow three divisibility rules. The boolean expression in this example mirrors those rules directly.
year = 2024
is_leap = (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
if is_leap:
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")