# write a function that takes # a list of animals and a list of sounds. # Use the given animals and sounds and # print the "Old MacDonald had a farm" song # # You may assume that the sizes of both lists are the same # (that is, the number of animals and sounds given are the same) # (https://www.youtube.com/watch?v=LIWbUjHZFTw) # # Old MacDonald had a farm # E I E I O # And on his farm he had a #animal# # E I E I O # With a #sound# #sound# here # And a #sound# #sound# there # Here a #sound#, there a #sound# # Everywhere a #sound# #sound# # Old MacDonald had a farm # E I E I O def macDonald(myanimals, mysounds): number = len(myanimals) i = 0 while i < number: # when to stop print("Old MacDonald had a farm E I E I O") print("And on his farm, he has a", myanimals[i], "E I E I O") print("With a", mysounds[i], "here, and a", mysounds[i], "there") print("Here a", mysounds[i], "there a ", mysounds[i], \ "everywhere a", mysounds[i], mysounds[i]) print("Old MacDonald had a farm E I E I O") print() i += 1 animals = ["pig", "horse", "chicken", "dino", "cat"] # 5 items sounds = ["oink", "neigh", "bawk", "ooo", "meow"] # 5 items macDonald(animals, sounds) print("\n ===== Let's rewrite the function, using a for loop ===== \n") def macDonald_for(myanimals, mysounds): number = len(myanimals) for i in range(number): print("Old MacDonald had a farm E I E I O") print("And on his farm, he has a", myanimals[i], "E I E I O") print("With a", mysounds[i], "here, and a", mysounds[i], "there") print("Here a", mysounds[i], "there a ", mysounds[i], "everywhere a", mysounds[i], mysounds[i]) print("Old MacDonald had a farm E I E I O") print() i += 1 animals = ["pig", "horse", "chicken", "dino", "cat"] # 5 items sounds = ["oink", "neigh", "bawk", "ooo", "meow"] # 5 items macDonald_for(animals, sounds)