from ml_quotes import quotes, authors, originals import random # assume you have the following: # work_text: a string that has been prepared for madlibs # # A string in quotes looks like this: # "To or not to . That is the ." # # The part of speech that needs to be replaced is indicated with < >. # # Write code that prompts the user for all the words needed to # complete the quote, and then prints out the new version of the # quote, in quotes. work_text = "To or not to . That is the ." n_replacements = work_text.count("<") finished = "" for n in list(range(n_replacements)): start_index = work_text.find("<") end_index = work_text.find(">") # everthing up to the first marker (<) gets copied into finished finished = finished + work_text[0:start_index] prompt = work_text[start_index+1:end_index] new_word = input("Please give me a "+prompt+": ") # word from user gets copied into finished finished = finished + new_word # update work_text to reflect what we've already processed work_text = work_text[end_index+1:] # don't forget the text at the end that comes after the last prompt finished = finished + work_text print("\""+finished+"\"")