RosettaCodeData/Task/Mad-Libs/11l/mad-libs.11l
2023-07-01 13:44:08 -04:00

13 lines
549 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

V template = <name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home.
F madlibs(template)
print("The story template is:\n"template)
V fields = sorted(Array(Set(re:<[^>]+>.find_strings(template))))
V values = input("\nInput a comma-separated list of words to replace the following items\n #.: ".format(fields.join(,))).split(,)
V story = template
L(f, v) zip(fields, values)
story = story.replace(f, v)
print("\nThe story becomes:\n\n"story)
madlibs(template)