If you read the section on function generators, try writing a generator with signature: leapyears(yearlist) The yearlist parameter is a sequence of year numbers, for example [1600, 1604, 1700, 1704, 1800, 1900, 1996, 2000, 2004]. Given this input the output would be the years, 1600, 1604, 1704, 1996, 2000, and 2004, one at a time. This can be done in about half a dozen lines. (Hint: Leap years are divisible by 4, but if divisible by 100, must also be divisible by 400.) Model answers for this chapter's exercises are in the file chap02/ answers.py.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here