Skip to content

Instantly share code, notes, and snippets.

@CaryInVictoria
Last active December 25, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaryInVictoria/7015265 to your computer and use it in GitHub Desktop.
Save CaryInVictoria/7015265 to your computer and use it in GitHub Desktop.
leap year problem
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