CMU Coding Bootcamp
at private/coded/push-mttnlwyrtnss 17 lines 697 B view raw
1def isLeapYear(year: int) -> bool: 2 """Return True if year is a leap year, False otherwise.""" 3 if year <= 0: 4 return False 5 # 4 years v 400 years v not 100 years v 6 return not (year % 4 or (year % 400 and not year % 100)) 7 8 9print("Testing isLeapYear()...", end="") 10assert isLeapYear(2024) == True 11assert isLeapYear(2023) == False 12assert isLeapYear(2020) == True 13assert isLeapYear(1900) == False # divisible by 100 but not by 400 14assert isLeapYear(2000) == True # divisible by 100 but also by 400 15assert isLeapYear(-2024) == False # non-positive years are not leap years 16assert isLeapYear(0) == False # non-positive years are not leap years 17print("Passed!")