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.

Respuesta :

Answer:

Statement given below in Python

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()

Answer:

user_input = input()

#Split the user input

#to obtain the input

#string and integer in

#the form of a list.

input_list = user_input.split()

while True:

   #Get the input string

   #from the list.

   input_string = input_list[0]

   

   #If the input string

   #is quit then, break the loop.

   if input_string == "quit":

       break

   #Otherwise, move

   #to the else case.

   else:

       #Get the input

       #integer from the list.

       input_integer = int(input_list[1])

       print("Eating "+str(input_integer)+ " "+input_string+" a day keeps the doctor away.")

   #Read and store

   #the user input.

   user_input = input()

   

   #Split the user input

   #to obtain the input

   #string and integer in

   #the form of a list.

   input_list = user_input.split()

Explanation: