# write a function that takes an animal and its sound, # use the given animal and sound and # print the "Old MacDonald had a farm song" # note: an animal is always given # but its sound is not # hint: think about the things that can be optional # practice writing function, with optional arguments # difference between print and return # practice conditional statements # Old MacDonald had a farm # E-I-E-I-O # And on his farm he had a cow # E-I-E-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 # E-I-E-I-O def old_macdonald(animal, sound=None): """ This function takes an animal and its sound and print an Old MacDonald had a farm song :param animal: :param sound: optional (default is None) :return: None """ print("=== call old_macdonald ===") old_macdonald("cow", "moo") # old_macdonald("pig", "oink") old_macdonald("pig") print("=== call old_macdonald and print the result ===") # notice that the function return nothing print(old_macdonald("cow", "moo")) print(old_macdonald("pig")) print("=================") # modify the function to return the song instead of print def old_macdonald2(animal, sound=None): """ This function takes an animal and its sound and return an Old MacDonald had a farm song :param animal: :param sound: optional (default is None) :return: string representing old macdonald song """ print("=== call old_macdonald2 ===") old_macdonald2("cow", "moo") # old_macdonald("pig", "oink") old_macdonald2("pig") # notice that the function doesn't print anything, it only returns # calling the function does not show anything on screen print("=== call old_macdonald2 and print the result ===") print(old_macdonald2("cow", "moo")) # old_macdonald("pig", "oink") print(old_macdonald2("pig"))