[Tutor] n.isalnum() is failing

János Juhász janos.juhasz at VELUX.com
Thu Jul 5 07:30:35 CEST 2007


Hi Terry

> "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 
exceptions
>   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 
logic
is to do it backward instead of thinking on the exceptions. 

def leap_year(year):
    if year%400 == 0: return True    # We said these years are always leap 
year
    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


ps
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?  ;)


Janos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070705/3e33dd34/attachment.html 


More information about the Tutor mailing list