Question

16.25 LAB 9A: Mad Lib - Loop Overview Objective Be able to implement a sentinel-controlled loop....

16.25 LAB 9A: Mad Lib - Loop

Overview

Objective

Be able to implement a sentinel-controlled loop.

Description

Remember from Lab 3C that Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways.

Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit.

Ex:

Enter a name: Eric
Enter a place: Lou & Harry's
Enter a number: 12
Enter a plural noun: cars
Enter an adjective: orange

Eric went to Lou & Harry's to buy 12 different types of cars
but unfortunately, the cars were all orange so Eric went back to Lou & Harry's to return them.

Do you want to quit [y/n]? n

Enter a name: Derek
Enter a place: JoAnn Fabrics and Crafts
Enter a number: 3
Enter a plural noun: sewing machines
Enter an adjective: pretty

Derek went to JoAnn Fabrics and Crafts to buy 3 different types of sewing machines
but unfortunately, the sewing machines were all pretty so Derek went back to JoAnn Fabric and Crafts to return them.

Do you want to quit [y/n]? y
Goodbye
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code(Python):

op='n'
while(op=='n'):
name= input('Enter a name:')
place= input('Enter a place:')
num= input('Enter a number:')
noun= input('Enter a plural noun:')
adj= input('Enter an adjective:')
print('\n'+name+' went to '+place+' to buy '+num+' different types of '+noun)
print('but unfortunately, the '+noun+' were all '+adj+' so '+name+' went back to '+place+' to return them.')
op=input('\nDo you want to quit [y/n]?')

print('Goodbye')

Explanation: The input and output part of program needs to be repeated many times and is thus kept in the while loop which works on the value stored in a variable op.While loop works till op=n. After every iteration of loop, new value of op is taken as input.

Output:

Add a comment
Know the answer?
Add Answer to:
16.25 LAB 9A: Mad Lib - Loop Overview Objective Be able to implement a sentinel-controlled loop....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to...

    16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to implement a sentinel-controlled loop. Description Remember from Lab 3C that Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Extend your program from Lab 3C that repeats asking the user for input and displaying the short story until the user wants to quit. Ex: Enter a name:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT