Description Leap years occur according to the following formula: a leap year is divisible by four, but not by one hundred, unless it is divisible by four hundred. For example, 1992, 1996, and 2000 are leap years, but 1993 and 1900 are not. The next leap year that falls on a century will be 2400. Input Your program should take a year as input. Output Your program should print whether the year is or is not a leap year. Sample Session What year: 1999 1999 is not a leap year. What year: 1988 1988 is a leap year. |
#! /usr/bin/env python
import operator
year = int(raw_input('What year:'))
if ( operator.mod(year,400)==0) or ((operator.mod(year,4)==0) and (operator.mod(year,100) <> 0)):
print '%d is a leap year.' %year
else :
print '%d is not a leap year.' %year
Reference :
leap year method
operator method
0 意見:
張貼留言