-
Notifications
You must be signed in to change notification settings - Fork 1
/
20qs.py
76 lines (60 loc) · 2.22 KB
/
20qs.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
months_list = ["january","february","march","april","may","june",
"july","august","september","october","november","december"]
print("I will try to guess your birth month. Please answer 'y' or 'n' to each question")
def answers_yes(letter):
"""removes words without that letter"""
for month in months_list[:]:
if letter not in month:
months_list.remove(month)
def answers_no(letter):
"""removes words with that letter"""
for month in months_list[:]:
if letter in month:
months_list.remove(month)
def question(letter):
"""asks the question and runs appropriate function"""
response = None
while response not in ("y", "n"):
response = input("\nDoes the month have the letter "+letter+" in it? ")
response = response.lower()
if response == 'y':
answers_yes(letter)
elif response == 'n':
answers_no(letter)
else:
print("please pick 'y' or 'n'")
#testing different letters to rule out months
question('a')
if len(months_list) >1:
for month in months_list:
if 'a' in month in months_list:
question('y')
if 'y' in month in months_list:
question('r')
if 'r' in month in months_list:
question('b')
else:
question('j')
else:
question('r')
if 'r' in month in months_list:
question('h')
else:
question('l')
else:
question('m')
for month in months_list:
if 'm' in month in months_list:
question('n')
if 'n' in month in months_list:
question('s')
else:
question('p')
else:
question('j')
if 'j' in month in months_list:
question('l')
else:
question('r')
print("\nIt's",months_list)
input("\n\nPress any key to exit ")