Sha256: 0f4d01ff3318a2d5ee430a13d1fbd61f3c290e63c9a1d67ab431d318c52f9f7d

Contents?: true

Size: 1.45 KB

Versions: 65

Compression:

Stored size: 1.45 KB

Contents

def chain():

    animals = ["fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"]

    phrases = [" wriggled and jiggled and tickled inside her.",
               "How absurd to swallow a bird!",
               "Imagine that, to swallow a cat!",
               "What a hog, to swallow a dog!",
               "Just opened her throat and swallowed a goat!",
               "I don't know how she swallowed a cow!",
               "She's dead, of course!"]

    old_lady = "I know an old lady who swallowed a "
    swallowed = "She swallowed the <animal> to catch the "
    die = "I don't know why she swallowed the fly. Perhaps she'll die."

    song = ""
    verse = ""
    chain = ""

    for number, animal in enumerate(animals):
        verse = old_lady + animal + ".\n"

        if number == 7:
            verse += phrases[6]
        else:
            if number == 0:
                chain = swallowed + animal + '.\n'
            elif number == 1:
                verse += "It" + phrases[0] + "\n"
                chain = chain.replace("<animal>", animal)
                verse += chain
                chain = swallowed+animal+" that"+phrases[0]+"\n"+chain
            else:
                verse += phrases[number-1] + "\n"
                chain = chain.replace("<animal>", animal)
                verse += chain
                chain = swallowed + animal + ".\n" + chain

            verse += die + "\n"

        verse += "\n"
        song += verse

    return song

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
trackler-2.2.1.110 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.109 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.108 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.107 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.106 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.105 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.104 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.103 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.102 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.101 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.100 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.99 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.98 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.97 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.96 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.95 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.94 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.93 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.92 tracks/python/exercises/food-chain/example.py
trackler-2.2.1.91 tracks/python/exercises/food-chain/example.py