id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

chanr@sfusd.edu pythonfunctionsseven > is_leap_year
prev  |  next  |  chance

This function should return true if the given year is a leap year and false otherwise. Only positive values will be used for years. Most years that are divisible by 4 are leap years, but there are exceptions. Years that are divisible by 100 are not leap years, unless they are also divisible by 400, in which case they are still a leap year! If we had a leap year every 4 years, it would over correct and our calendars would fall out of sync. To correct for this, years divisible by 100 are not counted as leap years (for instance, 1900 was not a leap year). However, this over corrects too much in the other direction! To avoid over correcting, we still count years divisible by 400 as leap years (for instance, 2000 was a leap year!)


is_leap_year(1998) → False
is_leap_year(2001) → False
is_leap_year(2004) → True

...Save, Compile, Run (ctrl-enter)

def is_leap_year(year):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy