Last active
August 29, 2015 14:11
-
-
Save danudey/710d0d437a78009c5371 to your computer and use it in GitHub Desktop.
Twelve lines of Christmas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
gifts = ("partridge in a pear tree", "turtle doves", "french hens", | |
"calling birds", "golden rings", "geese-a-laying", "swans-a-swimming", | |
"maids-a-milking", "ladies dancing", "lords-a-leaping", "pipers piping", | |
"drummers drumming",) | |
for i in xrange(1,len(gifts)+1): | |
print "On the {} day of Christmas, my true love gave to me:".format( | |
str(i)+("th" if 4<=i%100<=20 else {1:"st",2:"nd",3:"rd"}.get(i%10, "th"))) | |
for j, gift in list(enumerate(gifts[:i],1))[::-1]: | |
print " {} {}".format((j,("and a","a")[i==1])[j==1], gift) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes: