house.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
things = [
    ('house that Jack built', ''),
    ('malt', 'lay in'),
    ('rat', 'ate'),
    ('cat', 'killed'),
    ('dog', 'worried'),
    ('cow with the crumpled horn', 'tossed'),
    ('maiden all forlorn', 'milked'),
    ('man all tattered and torn', 'kissed'),
    ('priest all shaven and shorn', 'married'),
    ('rooster that crowed in the morn', 'woke'),
    ('farmer sowing his corn', 'kept'),
    ('horse and the hound and the horn', 'belonged to'),
]

def thats(n):
    """Return all the lines beginning with 'that' for verse n"""
    return [
        'that {verbed} the {noun}'.format(
            verbed=things[i][1],
            noun=things[i-1][0]
        )
        for i in range(n, 0, -1)
    ]

def verse(n):
    """Return the nth verse"""
    return '\n'.join(
        ['This is the {}'.format(things[n][0])] +
        thats(n)
    ) + '.'


def rhyme():
    """Return the full rhyme"""
    return '\n\n'.join(
        verse(n)
        for n in range(0, 12)
    )

Comments

Not fond of these song exercises...

helenst commented 4 June 2016 at 22:08 UTC

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