<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.14.2">
</HEAD>
<BODY>
<FONT COLOR="#000000">Hi </FONT><FONT COLOR="#000000"><TT><FONT SIZE="2">Janos</FONT></TT></FONT><FONT COLOR="#000000">,</FONT><BR>
<BR>
<TT><FONT SIZE="2"><FONT COLOR="#000000">Quote: Your logic is backward, and mine is the forward, isn't it?&nbsp; ;)</FONT></FONT></TT><BR>
<BR>
<FONT COLOR="#000000">The Story of My Life!</FONT><BR>
<BR>
<FONT COLOR="#000000">--Terry</FONT><BR>
<BR>
<BR>
On Thu, 2007-07-05 at 07:30 +0200, J&#225;nos Juh&#225;sz wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">Hi Terry</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; &quot;According to the Gregorian calendar, which is the civil calendar in use</FONT></FONT></TT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; today, years evenly divisible by 4 are leap years, with the exception of</FONT></FONT></TT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; centurial years that are not evenly divisible by 400.&quot;</FONT></FONT></TT><BR>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; def isLeapYear(y):</FONT></FONT></TT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; &nbsp; if y % 4 == 0: return True</FONT></FONT></TT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">As it always return True, if y%4 == 0, there is problem with the exceptions</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; &nbsp; if (y % 4 == 0) and not (y %100 == 0): return True</FONT></FONT></TT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&gt; &nbsp; else: return False</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <BR>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">I feel that, the cleanest way to translate the definition into Boolean logic</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">is to do it backward instead of thinking on the exceptions.</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">def leap_year(year):</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&nbsp; &nbsp; if year%400 == 0: return True &nbsp; &nbsp;# We said these years are always leap year</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&nbsp; &nbsp; if year%100 == 0: return False &nbsp; # the exception handled already</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&nbsp; &nbsp; if year%4 &nbsp; == 0: return True &nbsp; &nbsp;# no problem with the exceptions</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">&nbsp; &nbsp; return False &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # this it the default</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <BR>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">ps</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">hungarians name format: family name, christian name</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">hungarian date format: year/month/day</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">Your logic is backward, and mine is the forward, isn't it? &nbsp;;)</FONT></FONT></TT><FONT COLOR="#000000"> </FONT><BR>
    <BR>
    <BR>
    <TT><FONT SIZE="2"><FONT COLOR="#000000">Janos</FONT></FONT></TT>
<PRE>
<FONT COLOR="#000000">_______________________________________________</FONT>
<FONT COLOR="#000000">Tutor maillist  -  <A HREF="mailto:Tutor@python.org">Tutor@python.org</A></FONT>
<FONT COLOR="#000000"><A HREF="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</A></FONT>
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>