4.17 LAB: Mad Lib - loops
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.
Write a program that takes a string and an integer as input, and outputs a sentence using the input values as shown in the example below. The program repeats until the input string is quit and disregards the integer input that follows.
Ex: If the input is:
apples 5 shoes 2 quit 0
Solved 1 Answer
See More Answers for FREE
Enhance your learning with StudyX
Receive support from our dedicated community users and experts
See up to 20 answers per week for free
Experience reliable customer service
The language is not mentioned in the question. So, I am assuming it to be python. If it is some other language do let me know. Thank you Mad Libs is a type of word game in which a player/person prompts others for a list of words that are used to fill in blank spaces in a story. Given below is the solution to your question. def main(): #reading a line of text and splitting by white space to create a list of two tokens fields=input().split(' ') #looping until the first word is 'quit' in any case while fields[0].lower()!='quit': #displaying in the format 'Eating <second_value> <first_value> a day keeps the doctor away.' #assuming that there will always be 2 values in input string separated by space print('Eating {} {} a day keeps the doctor away.'.format(fields[1],fields[0])) # reading next line of text and splitting by white space fields = input().split(' ') #invoking main() method main() apples 5Eating 5 apples a day keeps the doctor away.Eating 2 shoes a day keeps the doctor away.Process finished with exit code 0 I hope your question is resolved. ...