<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># alternate version of madlibs2.py

# 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;."

# each item in worklist except for the one at index 0 originally started with &lt;
worklist = work_text.split('&lt;')
for i in list(range(1, len(worklist))):
    sublist = worklist[i].split('&gt;') # at 0 is the prompt; at 1 is the rest
    sublist[0]= input("Please give me a "+sublist[0]+": ") # replace with user input
    worklist[i] = ''.join(sublist)

finished = ''.join(worklist)

print("\""+finished+"\"")

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