DEV Community

Cover image for Old MacDonald
Scott Gordon
Scott Gordon

Posted on

1 1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay