DEV Community

Cover image for Old MacDonald
Scott Gordon
Scott Gordon

Posted on

Old MacDonald

# exercise1.py
#   This program prints the lyrics for five different animals to the
#   "Old MacDonald" song to demonstate functions.
# by: Scott Gordon

# Create functions for verses that repeat
def verse1():
    return "Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!"


def verse2(animal):
    return f"And on that farm he had a {animal}, Ee-igh, Ee-igh, Oh!"


def verse3(sound):
    return f"With a {sound}, {sound} here and a {sound}, {sound} there."


def verse4(sound):
    return f"Here a {sound}, there a {sound}, everywhere a {sound}, {sound}."


# Create a function to run all the functions through
def song_verse_creator(animal, sound):
    print(verse1())
    print(verse2(animal))
    print(verse3(sound))
    print(verse4(sound))
    print(verse1())

# Run 5 different functions
song_verse_creator("cow", "moo")
print()
song_verse_creator("chicken", "cluck")
print()
song_verse_creator("dog", "woof")
print()
song_verse_creator("duck", "quack")
print()
song_verse_creator("horse", "neigh")

Enter fullscreen mode Exit fullscreen mode

Photo by Zosia Korcz on Unsplash

Top comments (0)