Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The real Old McDonald song: Old McDonald Old McDonald had a farm, E-I-E-I-O. And on that farm he had a chicken, E-I-E-I-O. With a cluck-cluck

The "real" Old McDonald song:

Old McDonald

Old McDonald had a farm, E-I-E-I-O. And on that farm he had a chicken, E-I-E-I-O. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O.

Old McDonald had a farm, E-I-E-I-O. And on that 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. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O.

Old McDonald had a farm, E-I-E-I-O. And on that farm he had a duck, E-I-E-I-O. With a quack-quack here, and a quack-quack there. Here a quack, there a quack, everywhere a quack-quack. With a moo-moo here, and a moo-moo there. Here a moo, there a moo, everywhere a moo-moo. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O.

Starting points: old_mcdonald.py #startcode def title(): pass def verse(animal, sound): pass def query_verse(): return False 

#endcode

makeup_song1.py

#startcode

import old_mcdonald # driver function def main(): # print the title old_mcdonald.title() # print the first three verses old_mcdonald.verse('chicken', 'cluck') old_mcdonald.verse('cow', 'moo') old_mcdonald.verse('duck', 'quack') # ask for more verses while old_mcdonald.query_verse(): pass # say goodnight, gracie print('Thanks for singing with me.') # run the program main() 

#endcode

The task for the first part of the assignment is to complete the old_mcdonald module.

Some Important Notes:

The only changes you will make for the minimal and standard versions of the assignment are to the old_mcdonald.py module.

Remember to add the standard header comments to the module, old_mcdonald.

For the minimal version of the assignment, you simply the title and verse functions in old_mcdonald. The query_verse function is for the standard version of the assignment. For the minimal version, you can leave it alone.

For the verse function to print out the "real" verses to the song, it's going to have to have a way to "remember" the sounds from the previous verses. Use a list to hold the animal sounds. Since the list will need to be "shared" between different calls of the verse function, the list will need to be global. (The other option would be to have the list local to main, but then it would need to be passed as part of each call to verse.) When you declare the global variable, set its value to be an empty list.

The following code fragment gives an example of declaring the variable sounds and assigning an empty list to it.

sounds = []

The verse function shall not assign a value to the global variable sounds. On the other hand, it is perfectly fine for the verse function to call methods using the sounds variable. So, there is no reason to use the global keyword in your code. In fact, there is a deduction for using the global keyword in this assignment.

Some additional notes about the title and verse functions:

The title function shall print out two lines: one with "Old McDonald" and a second blank line.

The verse function shall print a blank line after the text of the verse.

Notice that the sounds are in the verse with the most recent animal's sound first and the the first animal's sound last, with the rest arranged in order between them.

Careful (thoughtful) use of a loop with the global list will make the verse function straight-forward.

Standard Version

For the standard version of the assignment, you will also implement the third function in the old_mcdonald module, namely, query_verse. This function will add a verse to the song by ask the user for an animal and its sound. It returns a Boolean value indicating if a new verse was printed out or not.

The query_verse function shall verify that the animal and sound supplied by the user are not blank, and also that they have not already been used within the song. If both the animal and the sound pass validation, print out a blank line, then call the verse function, passing the new animal and sound. Following the call to verse, the query_versefunction returns True. If either the animal or the sound fails validation, prompt again, up to five times. After five validation failures for the animal or five failures for the sound, the function returns False, indicating that no verse was added to the song. This is the user can mess up the animal up to four time and the sound up to four times and still have the verse printed. The next call to query_verse starts the error counters at zero again.

Sample Run

Here is an example of what the Standard assignment will look like, when run:

Old McDonald Old McDonald had a farm, E-I-E-I-O. And on that farm he had a chicken, E-I-E-I-O. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O. Old McDonald had a farm, E-I-E-I-O. And on that 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. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O. Old McDonald had a farm, E-I-E-I-O. And on that farm he had a duck, E-I-E-I-O. With a quack-quack here, and a quack-quack there. Here a quack, there a quack, everywhere a quack-quack. With a moo-moo here, and a moo-moo there. Here a moo, there a moo, everywhere a moo-moo. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O. Enter an animal: cow The animal cow is already been used. Please try again. Enter an animal: turkey Enter the sound the animal makes: gobble Old McDonald had a farm, E-I-E-I-O. And on that farm he had a turkey, E-I-E-I-O. With a gobble-gobble here, and a gobble-gobble there. Here a gobble, there a gobble, everywhere a gobble-gobble. With a quack-quack here, and a quack-quack there. Here a quack, there a quack, everywhere a quack-quack. With a moo-moo here, and a moo-moo there. Here a moo, there a moo, everywhere a moo-moo. With a cluck-cluck here, and a cluck-cluck there. Here a cluck, there a cluck, everywhere a cluck-cluck. Old McDonald had a farm, E-I-E-I-O. Enter an animal: The animal cannot be blank. Please try again. Enter an animal: The animal cannot be blank. Please try again. Enter an animal: The animal cannot be blank. Please try again. Enter an animal: The animal cannot be blank. Please try again. Enter an animal: The animal cannot be blank. Thanks for singing with me.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago

Question

What is quality of work life ?

Answered: 1 week ago

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago