Source

PythonDojo / Xmas2012 / twelve_days.py

#!/usr/bin/env python
# encoding: utf-8
"""
twelve_days.py

Created by Coding Dojo on 2012-12-16.
"""

ORDINALS = {
    1: "first",
    2: "second",
    3: "third",
    4: "fourth",
    5: "fifth",
    6: "sixth",
    7: "seventh",
    8: "eighth",
    9: "ninth",
    10: "tenth",
    11: "eleventh",
    12: "twelfth"
}

DAYS = [
    "A partridge in a pear tree",
    "Two turtle doves,",
    "Three French hens,",
    "Four colly birds,",
    "Five gold rings,",
    "Six geese a-laying,",
    "Seven swans a-swimming,",
    "Eight maids a-milking,",
    "Nine drummers drumming,",
    "Ten ladies dancing,",
    "Eleven pipers piping,",
    "Twelve lords a-leaping,"
]

def verse(number):
    result = []
    result.append("The %s day of Christmas" % ORDINALS[number])
    result.append("My true love gave to me")
    result.extend(reversed(DAYS[1:number]))

    if number > 1:
        result.append("And " + DAYS[0].lower())
    else:
        result.append(DAYS[0])

    return '\n'.join(result)

def song():
    return '\n\n'.join(verse(i) for i in range(1, 13))

if __name__ == '__main__':
	print song()