nick34992
4/17/2017 - 6:08 PM

Python: Is Year Number a Leap Year?

Python: Is Year Number a Leap Year?

# Is given year a leap year? True or False
def is_leap(year):
    leap = False
    if year % 4 == 0:
        leap = True
        if year % 100 == 0 and year % 400 != 0:
            leap = False
    return leap

print(is_leap(1991))  # False
print(is_leap(1992))  # True (divisible by 4)
print(is_leap(2000))  # True (400 yr leap cycle)
print(is_leap(2100))  # False (divisible by 100)
print(is_leap(2400))  # True (400 yr leap cycle)