6.3 - Old MacDonald
Problem
Procedures can have multiple parameters. Write a program that will display the nursery rhyme Old Macdonald Had a Farm.
The program should use a procedure that takes two parameters (animal, sound).
Using the problem description and design, implement the program.
Example - Multiple parameters
def welcome(forename, surname):
print("Hello", forename, surname)
# Main
welcome("Jane", "Smith")
welcome("John", "Smith")
Old MacDonald had a farm Ee, i, ee, i, o And on his farm he had some cows Ee, i, ee, i, o With a moo-moo here and a moo-moo there Here a moo, there a moo, everywhere a moo-moo Old MacDonald had a farm Ee, i, ee, i, o And on his farm he had some chicks Ee, i, ee, i, o With a cluck-cluck here and a cluck-cluck there Here a cluck, there a cluck, everywhere a cluck-cluck Old MacDonald had a farm Ee, i, ee, i, o And on his farm he had some sheep Ee, i, ee, i, o With a baaa-baaa here and baaa-baaa there Here a baaa-baaa, there a baaa-baaa, everywhere a baaa-baaa Old MacDonald had a farm Ee, i, ee, i, o
| 1 | Chorus | IN | |
| 2 | Verse | IN | animal, sound |
1.1 display “Old MacDonald had a farm”
1.2 display “Ee, i, ee, i, o”
2.1 display “And on his farm he had some” + animal
2.2 display “Ee, i, ee, i, o”
2.3 display “With a” + sound + sound + “here and a” + sound + sound + “there”
2.4 display “Here a” + sound +”, there a” + sound + “, everywhere a” + sound + sound
# Main
chorus()
verse("Cow", "Moo")
chorus()
verse("Chicken", "Cluck")
chorus()
verse("Sheep", "Baa")
chorus()
def chorus():
print("Old MacDonald had a farm")
print("Ee, i, ee, i, o")
print()
def verse(animal, sound):
print("And on his farm he had some " + animal)
print("Ee, i, ee, i, o")
print("With a " + sound + sound + " here and a " + sound + sound + " there")
print("Here a " + sound +", there a " + sound + ", everywhere a " + sound + sound)
print()
# Main
chorus()
verse("Cow", "Moo")
chorus()
verse("Chicken", "Cluck")
chorus()
verse("Sheep", "Baa")
chorus()