Leap Years (2) X91228


Statement
 

pdf   zip

html

Write a function leapyear(y) that tells us whether y, as a year, is a leap year. Argument y is an int between 1800 and 9999. The function must return a boolean.

A leap year has 366 days, instead of 365. After the Gregorian reform, the leap years are those multiple of four that do not end with two zeros (i.e. are not multiples of 100), and also the years ending with two zeros such that, after removing these two zeros, are divisible by four (i.e. are multiples of 400). Thus, 1800 and 1900, although being multiples of four, were not leap years (because they are multiples of 100); by contrast, 2000 was a leap year (because despite being multiple of 100, it is also multiple of 400).

Sample session
>>> leapyear(1999)
False
>>> leapyear(1968)
True
>>> leapyear(2000)
True
>>> leapyear(1800)
False
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python