[Tutor] n.isalnum() is failing
janos.juhasz at VELUX.com
Thu Jul 5 07:30:35 CEST 2007
> "According to the Gregorian calendar, which is the civil calendar in use
> today, years evenly divisible by 4 are leap years, with the exception of
> centurial years that are not evenly divisible by 400."
> def isLeapYear(y):
> if y % 4 == 0: return True
As it always return True, if y%4 == 0, there is problem with the
> if (y % 4 == 0) and not (y %100 == 0): return True
> else: return False
I feel that, the cleanest way to translate the definition into Boolean
is to do it backward instead of thinking on the exceptions.
if year%400 == 0: return True # We said these years are always leap
if year%100 == 0: return False # the exception handled already
if year%4 == 0: return True # no problem with the exceptions
return False # this it the default
hungarians name format: family name, christian name
hungarian date format: year/month/day
Your logic is backward, and mine is the forward, isn't it? ;)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor