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
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:
16.25 LAB 9A: Mad Lib - Loop Overview Objective Be able to implement a sentinel-controlled loop....
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:...