60.8k views
2 votes
4.15 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 integer as input, and outputs a sentence using those items as below. The program repeats until the input is quit 0. Ex: If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps the doctor away. Eating 2 shoes a day keeps the doctor away.

2 Answers

4 votes

Final answer:

The question involves writing a Mad Libs program using loops in Computers and Technology to generate sentences from user inputs until 'quit 0' is entered. The program requires understanding of loops and string manipulation in programming.

Step-by-step explanation:

The subject of your question relates to creating a Mad Libs program using loops, which falls under the category of Computers and Technology. A Mad Lib is a phrasal template word game where one player prompts others for a list of words to substitute for blanks in a story before reading aloud. The goal of your lab exercise is to write a program that takes a string and an integer as input, then generates a sentence using these inputs in a humorous way. The program should continue to prompt for inputs until the user enters 'quit 0'. For example:

Input: apples 5

Output: Eating 5 apples a day keeps the doctor away.

Input: shoes 2

Output: Eating 2 shoes a day keeps the doctor away.

To achieve this, you will need to master the use of loops to repeatedly ask for input and utilize string concatenation or formatting to construct the output sentences.

User Jason Maggard
by
3.9k points
6 votes

Answer:

Statement given below in Python

Step-by-step explanation:

if __name__ == '__main__':

user_input = input()

while True: //while loop for splitting input

item = user_input.split()[0]

item_count = int(user_input.split()[1])

if item.lower() == "quit":

break //ends the loop

print("Eating " + str(item_count) + " " + item + " a day keeps the doctor away.")

user_input = input()

User Murtuza Z
by
4.2k points