Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f048fcc

Browse files
committed
bugfix: article not handled
1 parent a598641 commit f048fcc

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

17_mad_libs/mad.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pprint import pprint
1212
import sys
1313

14+
1415
# --------------------------------------------------
1516
def get_args():
1617
"""Get command-line arguments"""
@@ -33,7 +34,6 @@ def get_args():
3334
nargs="*",
3435
default=None)
3536

36-
3737
return parser.parse_args()
3838

3939

@@ -57,23 +57,19 @@ def main():
5757

5858
match = re.findall('(<([^<>]+)>)', text)
5959

60-
if len(match) == 0:
60+
if not match:
6161
print(f'"{pos_arg.name}" has no placeholders.', file=sys.stderr)
6262
sys.exit(1)
6363

64-
65-
if not inputs:
66-
inputs = [input(f"Geef waarde voor {b}:" ) for a,b in match]
67-
6864
# print(inputs)
6965

7066
# pprint(match)
7167

7268
# print('text before:'+text)
73-
inputs.reverse()
74-
for a, name in match:
75-
val = inputs.pop()
76-
text = re.sub('<[^<>]+>', val, text, 1)
69+
for placeholder, name in match:
70+
article = "a" if name[0].lower() in 'aeoiu' else "an"
71+
val = inputs.pop(0) if inputs else input("Give me {} {} ".format(article, name))
72+
text = re.sub(placeholder, val, text, 1)
7773

7874
print(text)
7975

0 commit comments

Comments
 (0)