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
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:
output:
# for any query ask in comment and if you like the answer please give an upvote :)
16.25 LAB 9A: Mad Lib - Loop (program in Python 3) Overview Objective Be able to...
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:...