Skip to content

Instantly share code, notes, and snippets.

@calthoff
Created April 5, 2018 03:13
Show Gist options
  • Select an option

  • Save calthoff/32c0aa26435fcef90dcf369ab16cc898 to your computer and use it in GitHub Desktop.

Select an option

Save calthoff/32c0aa26435fcef90dcf369ab16cc898 to your computer and use it in GitHub Desktop.
import re
text = """Giraffes have aroused
the curiosity of __PLURAL_NOUN__
since earliest times. The
giraffe is the tallest of all
living __PLURAL_NOUN__, but
scientists are unable to
explain how it got its long
__PART_OF_THE_BODY__. The
giraffe's tremendous height,
which might reach __NUMBER__
__PLURAL_NOUN__, comes from
it legs and __BODYPART__.
"""
def mad_libs(mls):
hints = re.findall("__.*?__", mls)
if hints is not None:
for word in hints:
q = "Enter a {}".format(word)
new = input(q)
mls = mls.replace(word, new, 1)
print('\n')
mls = mls.replace("\n", "")
print(mls)
else:
print("invalid mls")
mad_libs(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment