Hi Janos, Quote: Your logic is backward, and mine is the forward, isn't it? ;)
The Story of My Life! --Terry On Thu, 2007-07-05 at 07:30 +0200, János Juhász wrote: > > 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 > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor