<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># assume you have the following:
# work_text: a string that has been prepared for madlibs
#
# A string in quotes looks like this:
# "To &lt;verb&gt; or not to &lt;verb&gt;. That is the &lt;noun&gt;."
#
# The part of speech that needs to be replaced is indicated with &lt; &gt;.
# 
# 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 &lt;verb&gt; or not to &lt;verb&gt;. That is the &lt;noun&gt;."

n_replacements = work_text.count("&lt;")

finished = ""
for n in list(range(n_replacements)):
    start_index = work_text.find("&lt;")
    end_index = work_text.find("&gt;")

    # everthing up to the first marker (&lt;) 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+"\"")

</pre></body></html>