-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmad_libs.py
More file actions
30 lines (24 loc) 路 794 Bytes
/
Copy pathmad_libs.py
File metadata and controls
30 lines (24 loc) 路 794 Bytes
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
def load_template(filename):
with open(filename, 'r') as file:
return file.read()
def get_placeholders(template):
import re
return re.findall(r'{(.*?)}', template)
def get_user_inputs(placeholders):
inputs = {}
for ph in placeholders:
user_input = input(f"Enter a {ph.replace('_', ' ')}: ")
inputs[ph] = user_input
return inputs
def fill_template(template, inputs):
return template.format(**inputs)
def main():
template = load_template('mad_libs_template.txt')
placeholders = get_placeholders(template)
user_inputs = get_user_inputs(placeholders)
final_story = fill_template(template, user_inputs)
print("\n馃帀 Your Mad Libs Story:")
print("-" * 40)
print(final_story)
if __name__ == "__main__":
main()