Question

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: 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:

while True:
# ask user for name
name = input("Enter a name: ")
# ask user for place
place = input("Enter a place: ")
# ask user for a number
number = input("Enter a number: ")
# ask user for a noun
noun = input("Enter a plural noun: ")
# ask user for an adjective
adjective = input("Enter an adjective: ")
print()
# print the messege
print(name + " went to "+place+" to buy " + number + " different types of " + noun +
" but unfortunately, the " + noun + " were all " + adjective + " so " + name + " went back to " + place + " to return them.")
print()
# ask user if want to continue
choice = input("Do you want to quit [y/n]? ")
# if choice is n then break from loop
if choice == 'n':
break

print("Goodbye")

screenshots:

main.py saved 1 while True: ask user for name name = input(Enter a name: ) # ask user for place place = input(Enter a plac

output:

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

# for any query ask in comment and if you like the answer please give an upvote :)

Add a comment
Know the answer?
Add Answer to:
16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to...
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 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:...

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