Please, need help for this lab and use in python 3.4.1 Standard Version For the
ID: 639913 • Letter: P
Question
Please, need help for this lab and use in python 3.4.1
Standard Version
For the standard version:
Complete all the work for the minimal version.
Additionally, write a fourth function function that shall ask the user for an animal and its sound.
After collecting this information from the user, the new function shall print out another verse with the user-provided animal and sound values.
There is no input validation needed for the user's input for animal or sound.
The new function shall not call the print function to print out the verse. Instead, the new function shall call the verse function to generate its output.
In main, following the other function calls, call your new function. Note, this prints out a fourth verse to the song.
In main, following the call to the new verse function, the script shall ask the user if they want a fifth verse. Depending on the user's answer, the new verse function shall be called a second time.
This question about the fifth verse shall expect the answers: yes / no.
It is reasonable to tell the users what the expected values are.
The code should be robust enough to take some default action if the user doesn't give one of the "expected" answers.
The default action shall be to prompt for the animal and sound for the fifth verse.
The last two three bullet points can be translated as:
There are only two possible answers for the "Do you want a fifth verse?" question. Tell the user what the choices are. If the user picks one of them, do that. If the user's input doesn't match either of your two choices, assume that the user wants to do a fifth verse.
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.
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.
Old McDonald had a farm, E-I-E-I-O.
Enter an animal: horse
Enter the sound the horse makes: neigh
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a horse, E-I-E-I-O.
With a neigh-neigh here, and a neigh-neigh there.
Here a neigh, there a neigh, everywhere a neigh-neigh.
Old McDonald had a farm, E-I-E-I-O.
Do you want to have a fifth verse (yes/no)? nah
Enter an animal: pig
Enter the sound the pig makes: oink
Old McDonald had a farm, E-I-E-I-O.
And on that farm he had a pig, E-I-E-I-O.
With a oink-oink here, and a oink-oink there.
Here a oink, there a oink, everywhere a oink-oink.
Old McDonald had a farm, E-I-E-I-O.
In this example, for the obligatory fourth verse, the user entered horse/neigh. Then the user was asked about the fifth verse. The "acceptable answers" are "yes" and "no", as indicated in the question. The user's response was "nah". Since it doesn't match either of the expected answers ("yes" or "no"), the default action (the assumption) is to call the new function and get the animal and sound for a fifth verse. The user entered pig/oink for the fifth verse.
Explanation / Answer
def verse(name, sound):
print('Old McDonald had a farm, E-I-E-I-O.')
print('And on that farm he had a ' + name + ', E-I-E-I-O.')
print('With a ' + sound + '-' + sound + ' here, and a ' + sound + '-' + sound +' there.')
print('Here a ' + sound + ', there a ' + sound + ', everywhere a ' + sound + '-' + sound + '.')
print('Old McDonald had a farm, E-I-E-I-O. ')
def main():
verse('chicken', 'cluck')
verse('cow', 'moo')
verse('duck', 'quack')
name = input('Enter an animal: ')
sound = input('Enter the sound the horse makes: ')
print(' ')
verse(name, sound)
while True:
option = input('Do you want to have a fifth verse (yes/no)? ')
if option != 'no':
name = input('Enter an animal: ')
sound = input('Enter the sound the horse makes: ')
print(' ')
verse(name, sound)
else:
break
main()