Details of this Paper

Assignment11

Description

solution


Question

Assignment 11: Children's Songs, the Reprise;This assignment is designed to exercise a number of concepts and ideas that we have worked with this quarter. Given the typical crunch at the end of the quarter, this assignment is actually a bit shorter than some of the other assignments.;For the Minimal and Standard versions of this assignment, you will write an updated version of Old McDonald, that was Assignment 3. What we did in Assignment 3 was a simplified version of the song. For this assignment, we'll update output the song as it is sung.;The Challenge version adds another refactoring of There was an Old Lady, like Assignment 4, but this time using tuples.;Overview;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.;The primary difference between this version and the previous is that the sounds on the farm are cumulative, we have more sounds as we add more animals.;Minimal Version;Download the starting point code for Old McDonald;assign11.py;assign11_song1.py;The driver for this is assign11_song1.py. Here is the code for it;import assign11;# driver function;def main();# print the title;assign11.title();# print the first three verses;assign11.verse('chicken', 'cluck');assign11.verse('cow', 'moo');assign11.verse('duck', 'quack');# ask for more verses;while assign11.query_verse();pass;# say goodnight, gracie;print('Thanks for singing with me.');# run the program;main();Notice that this uses a module, the other file, assign11.py. Here is its code;def title();pass;def verse(animal, sound);pass;defquery_verse();return False;The task for the first part of the assignment is to complete the assign11 module.;(Participation fodder: What's the source for the "odd comment" in assign11_song1.py?);The only changes you will make for the minimal and standard versions of the assignment are to the assign11.py module.;For the minimal version of the assignment, you simply the title and verse functions in assign11. 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 assign11 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_verse function 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.;Challenge Version;For the challenge version of the assignment, you must complete the Minimal/Standard version first. Submitting the Challenge version without the Minimal/Standard version will only be worth 2 functionality points.;Download the starting point code for the challenge version;assign11c.py;assign11_song2.py;The driver script is assign11_song2.py;import assign11c;# the driver function;def main();# print out the title;assign11c.title();# print out the verses;for num in range(len(assign11c.ANIMALS));assign11c.verse(num);# run the program;main();As before, your task is to complete the module code, this time, in assign11c.;The assign11c module declares the following two global tuples;ANIMALS = ('fly.', 'spider,', 'bird.', 'cat.;dog.', 'goat.', 'cow.', 'horse.');LINES = ('I don\'t know why she swallowed the fly.;That wriggled and jiggled and tickled inside her.;How absurd to swallow a bird.;Imagine that to swallow a cat.;My, what a hog, to swallow a dog.;She just opened her throat and in walked the goat.;I don\'t know how she swallowed a cow.;She\'s dead, of course.');Notice that the punctuation irregularity with "spider" has been incorporated into the ANIMALS list.;Additionally, there are two functions within assign11c;def title();pass;def verse(n);pass;In "high-geek" fashion, we'll use the number zero to refer to the first verse. Then, this script prints the following;I Know an Old Lady;I know an old lady who swallowed a fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;I know an old lady who swallowed a spider;That wriggled and jiggled and tickled inside her.;She swallowed the spider to catch the fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;I know an old lady who swallowed a bird.;How absurd to swallow a bird.;She swallowed the bird to catch the spider;That wriggled and jiggled and tickled inside her.;She swallowed the spider to catch the fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;I know an old lady who swallowed a cat.;Imagine that to swallow a cat.;She swallowed the cat to catch the bird.;She swallowed the bird to catch the spider;That wriggled and jiggled and tickled inside her.;She swallowed the spider to catch the fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;I know an old lady who swallowed a dog.;My, what a hog, to swallow a dog.;She swallowed the dog to catch the cat.;She swallowed the cat to catch the bird.;She swallowed the bird to catch the spider;That wriggled and jiggled and tickled inside her.;She swallowed the spider to catch the fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;I know an old lady who swallowed a goat.;She just opened her throat and in walked the goat.;She swallowed the goat to catch the dog.;She swallowed the dog to catch the cat.;She swallowed the cat to catch the bird.;She swallowed the bird to catch the spider;That wriggled and jiggled and tickled inside her.;She swallowed the spider to catch the fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;I know an old lady who swallowed a cow.;I don't know how she swallowed a cow.;She swallowed the cow to catch the goat.;She swallowed the goat to catch the dog.;She swallowed the dog to catch the cat.;She swallowed the cat to catch the bird.;She swallowed the bird to catch the spider;That wriggled and jiggled and tickled inside her.;She swallowed the spider to catch the fly.;I don't know why she swallowed the fly.;Perhaps she'll die.;There was an old lady who swallowed a horse.;She's dead, of course.;Minimize the number of if statements in the verse. The minimum is two. You shouldn't need any helper functions.;Notice both title and verse print a blank line for aesthetic purposes.

 

Paper#69257 | Written in 18-Jul-2015

Price : $32
SiteLock