-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmad_Libs.py
More file actions
52 lines (41 loc) · 1.5 KB
/
mad_Libs.py
File metadata and controls
52 lines (41 loc) · 1.5 KB
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
43
44
45
46
47
48
49
50
51
52
'''
Author: Zain Raza
madLibs.py:
Simulates a game of Mad Libs using Python.
Date Due: Tuesday, September 3 2019
'''
import pyfiglet # module used for ASCII art
def init_blanks(diction, list):
for key in list:
diction[key] = input(key)
while not diction[key].isalpha():
print("Invalid input.")
diction[key] = input("Please try again: ")
def print_full_story(list_of_lines, diction, dict_keys):
key_word = ""
for i in range(len(list_of_lines)):
key_word = dict_keys[i] # traverses the keys in the dictionary
green_text = "\033[1;32;40m{}\x1b[0m".format(diction[key_word])
list_of_lines[i] += green_text # dict value appends list element
for line in list_of_lines:
sentence = line + "." # finishes sentence with punctuation
print(sentence)
blanks = {
"Enter a noun: ": "",
"Enter a verb: ": "",
"Enter an adjective: ": "",
"Enter an adverb: ": "",
"Enter a preposition: ": ""
}
story_list = [
"Kevin loved his home in the suburbs of ",
"He spent everyday doing his favorite activity, ",
"However, one day Kevin was abducted by someone who was very ",
"Never to fear! The police took up the search for Kevin ",
"Then Kevin was found, and joyous became the owner he was reunited "
]
list_of_keys = list(blanks.keys())
init_blanks(blanks, list_of_keys)
title = pyfiglet.figlet_format("The Search for Kevin the Dog", font="slant")
print(title)
print_full_story(story_list, blanks, list_of_keys)