Question
In Python 3 Using this script import old_mcdonald def main(): old_mcdonald.title() old_mcdonald.verse('chicken', 'cluck') old_mcdonald.verse('cow', 'moo') old_mcdonald.verse('duck', 'quack') #dictionary to hold the sounds that are used
In Python 3
Using this script
import old_mcdonald def main(): old_mcdonald.title() old_mcdonald.verse('chicken', 'cluck') old_mcdonald.verse('cow', 'moo') old_mcdonald.verse('duck', 'quack') #dictionary to hold the sounds that are used sounds = {'chicken':'cluck','cow':'moo','duck':'quack'} # names is a list containing name in order names = ['chicken','cow','duck'] while old_mcdonald.query_verse(): # You can replace below option with this #option = input('Do you want to have a {} verse (yes/no)? '.format(len(names)) option = input('Do you want to have a fifth verse (yes/no)? ') #if the option is yes if option == 'yes': name = input('Enter an animal: ') #check if the name is blank if name == '': print('The animal cannot be blank') #check if the name is already present # improved your code for checking names # elif name == 'cow' or name == 'chicken' or name == 'duck': elif name in names: print('The animal is already been used') else: #to enter sound11 sound = input('Enter the sound the it makes: ') sounds[name] = sound names.append(name) print(' ') for name in names: old_mcdonald.verse(name, sounds[name]) else: break print('Thanks for singing with me.') #when all the operations are over # run the program main()
And this script
def title(): print('Old McDonald') print(' ') pass
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('With a cluck-cluck here, and a cluck-cluck there.') print('Here a cluck, there a cluck, everywhere a cluck-cluck.') print('Old McDonald had a farm, E-I-E-I-O. ') pass
def query_verse(): return True
I need it to help secure the following exception and as well to verify against blank input ie spaces
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.
the exception output shall look like
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.
overall output should look like
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: cow The animal cow is already been used. 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. Please try again. Enter an animal: The animal cannot be blank.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started