Write a program to print the lyrics of the song \"Old MacDonald.\" Your program
ID: 3607075 • Letter: W
Question
Write a program to print the lyrics of the song "Old MacDonald." Your program should print the lyrics for five different animals, similar to the verse below. Old MacDonald had a farm, Ee-igh, Ee-igh, Oh! And on that farm he had a cow, Ee-igh, Ee-igh, Oh! 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-igh, Ee-igh, Oh! You are going to create a function for each of the moving parts of this song: (1) eieio, (2) refrain (Old MacDonald had a farm), (3) hada (And on that farm he had a), (4) witha (make the sounds), (5) verse You will then loop in the main function to read through a list of animals and their sounds. 1. Add comments at the top with file name: lab6_animal_YourLastName.py, your name, date, course section, etc. 2. Make sure to have the correct indentation for functions. Don't copy/paste the following codes, which will cause format errors within Python. Just type them one by one carefully. 3. Create the main function: def main(): for a,n in [("cow", "moo"), ("pig", "oink"), ("horse", "nay"), ("sheep", "baa"), ("chicken", "cluck"): #Note: This is all on one line verse(a, n)Explanation / Answer
NOTE: when you copy & paste the code to your editor verify whethere the indentation is properly set as shown below. If not you will get indentation error. (Mostly it should be same, you don't have to do anything.)
################# UPDATE THE BELOW COMMENT ############
# lab6_animal_<YOUR LAST NAME>, <NAME>, 01-NOV-2017, <COURSES SECTION>
def main():
for a,n in [("cow", "moo"), ("pig", "oink"), ("horse", "nay"), ("sheep", "baa"), ("chicken", "cluck")]:
verse(a, n)
print
def verse(animal, noise):
refrain()
hada(animal)
witha(noise)
refrain()
def refrain():
print "old MacDonald had a farm,",eieio()
def eieio():
return "Ee-igh, Ee-igh, Oh!"
def hada(animal):
print "And on that farm he had a",animal+",",eieio()
def witha(noise):
noisecomma = noise+","
noise2 = noisecomma+" "+noise
print "With",noise2,"here and a",noise2,"there."
# remove ' ' in below line if you wan't this complete sentence to be in same line
print "Here a", noisecomma,"there a",noisecomma," everywhere a",noise2+"."
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.