from ml_quotes import quotes, authors, originals import random # assume you have the following: # quotes: a list of strings that have been prepared for madlibs # originals: a list of the original quotes # authors: a list of the authors of said quotes # # 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 randomly picks a quote from the quotes list, prompts the # user for all the words needed to complete the quote, and then prints out # both the original and the new version of the quote, in quotes. def print_quote(quote, author): print("\""+quote+"\" --"+author) num_quotes = len(quotes) random_num = random.randint(0, num_quotes-1) quote = quotes[random_num] n_replacements = quote.count("<") new_quote = "" for n in list(range(n_replacements)): start_index = quote.find("<") end_index = quote.find(">") new_quote = new_quote + quote[0:start_index] prompt = quote[start_index+1:end_index] new_word = input("Please give me a "+prompt+": ") new_quote = new_quote + new_word quote = quote[end_index+1:] print("the original:") print_quote(originals[random_num], authors[random_num]) print("your quote:") print_quote(new_quote, authors[random_num])