twelve_days.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
GIFTS = {
    1: "a Partridge in a Pear Tree",
    2: "two Turtle Doves",
    3: "three French Hens",
    4: "four Calling Birds",
    5: "five Gold Rings",
    6: "six Geese-a-Laying",
    7: "seven Swans-a-Swimming",
    8: "eight Maids-a-Milking",
    9: "nine Ladies Dancing",
    10: "ten Lords-a-Leaping",
    11: "eleven Pipers Piping",
    12: "twelve Drummers Drumming",
}

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',
}


def verse(n):
    lines = [
        "On the %s day of Christmas my true love gave to me" % ORDINALS[n]
    ]

    # Add all the gifts except for day 1
    lines.extend(GIFTS[i] for i in range(n, 1, -1))

    # Day 1 (last line) might have an 'and'
    lines.append(GIFTS[1] if n == 1 else 'and %s' % GIFTS[1])

    return ', '.join(lines) + '.\n'


def verses(m, n):
    return '\n'.join(verse(i) for i in range(m, n + 1)) + '\n'


def sing():
    return verses(1, 12)

Comments


You're not logged in right now. Please login via GitHub to comment