Leap year

Gene Heskett gheskett at wdtv.com
Sat Sep 27 00:08:01 EDT 2014


On Friday 26 September 2014 23:49:43 Seymore4Head did opine
And Gene did reply:
> Still practicing.  Since this is listed as a Pseudocode, I assume this
> is a good way to explain something.  That means I can also assume my
> logic is fading with age.
> http://en.wikipedia.org/wiki/Leap_year#Algorithm
> 
> Me trying to look at the algorithm, it would lead me to try something
> like:
> if year % 4 !=0:
> 	return False
> elif year % 100 !=0:
> 	return True
> elif year % 400 !=0:
> 	return False
> 
> ****   Since it is a practice problem I have the answer:
> def is_leap_year(year):
> return ((year % 4) == 0 and ((year % 100) != 0 or (year % 400) == 0))
> 
> I didn't have any problem when I did this:
> 
> if year % 400 == 0:
> 	print ("Not leap year")
> elif year % 100 == 0:
> 	print ("Leap year")
> elif year % 4 == 0:
> 	print ("Leap year")
> else:
> 	print ("Not leap year")

Which is, except for language syntax to state it, exactly the same as is 
quoted for this problem in the original K&R C manual.  Is there anything 
new?

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS



More information about the Python-list mailing list