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
UPPERCASE_LETTERS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
LOWERCASE_LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
def uppercase(word):
out = ""
for x in word:
if x in LOWERCASE_LETTERS:
out += UPPERCASE_LETTERS[LOWERCASE_LETTERS.index(x)]
else:
out += x
return out
def convert_list_to_strs(lst):
lst_copy = []
for x in lst:
lst_copy.append(str(x))
return lst_copy
def is_answer(s, yn):
return s is not None and len(s) > 0 and uppercase(s[0]) in yn
def prompt_yes_no(prompt):
result = None
while not is_answer(result, set(["Y", "N"])):
result = input(prompt)
return is_answer(result, set(["Y"]))
def ask_for_choice(prompt, valid_choices):
choices = convert_list_to_strs(valid_choices)
choice = None
while not choice:
proposed = input(prompt)
if proposed in choices:
choice = proposed
else:
print("That's not a valid choice! Try one of: " +
", ".join(choices) + ".")
return proposed