[Tutor] [Fwd: [Fwd: Re: n.isalnum() is failing]]
Terry
terry.kemmerer at gmail.com
Sat Jul 7 00:50:52 CEST 2007
Hi Alan,
Yes! That is succinct and sweet! I think I like that one the best of
all!
Terry
-------- Forwarded Message --------
From: Alan Gauld <alan.gauld at btinternet.com>
To: tutor at python.org
Subject: Re: [Tutor] n.isalnum() is failing
Date: Thu, 5 Jul 2007 10:17:16 +0100
"János Juhász" <janos.juhasz at VELUX.com> wrote
>> def isLeapYear(y):
>> if y % 4 == 0: return True
> As it always return True, if y%4 == 0, there is problem with the
> exceptions
My original function had %400 not %4 so it worked.
>> 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 # these 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
But I rather like this one since the combined and/not expression
is less clear and more prone to confusion.. And in fact it can be
simplified even further:
def isLeapYear(y):
if y % 400: return True
if y % 100: return False
return y % 4 == 0
> 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? ;)
:-)
Alan G.
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070706/41b6bdad/attachment.htm
More information about the Tutor
mailing list