Last active
December 25, 2015 17:48
-
-
Save CaryInVictoria/7015265 to your computer and use it in GitHub Desktop.
leap year problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def leap_year(y): | |
if y % 400 == 0: | |
return True | |
if y % 100 == 0: | |
return False | |
if y % 4 == 0: | |
return True | |
return False | |
# or | |
def leap_year(y): | |
return y % 400 == 0 or (y % 100 != 0 and y % 4 == 0) | |
def report_leap_year(y): | |
if leap_year(y): | |
print("{0} is a leap year".format(y)) | |
else: | |
print("{0} is not a leap year".format(y)) | |
report_leap_year(2000) # => 2000 is a leap year | |
report_leap_year(1900) # => 1900 is not a leap year | |
report_leap_year(2012) # => 2012 is a leap year | |
report_leap_year(2013) # => 2013 is not a leap year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment