-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMad_libs.py
42 lines (38 loc) · 957 Bytes
/
Mad_libs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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):
"""
:param mls: String
with parts the user
should fill out surrounded
by double underscores.
Underscores cannot
be inside hint e.g., no
__hint_hint__ only
__hint__.
"""
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)