Skip to content

Commit 56ac849

Browse files
Lane HesserLane Hesser
authored andcommitted
PCC02 LaneHesser
1 parent 506ee28 commit 56ac849

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

02/LaneHesser/game.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,27 @@ def draw_letters():
5454

5555
def get_user_input(draw):
5656
"""Asks the player to form a word with one or more letters from draw."""
57-
print('Letters drawn:', *draw)
58-
word = input('Form a valid word: ').lower()
59-
60-
if word not in DICTIONARY:
61-
raise ValueError(f'{word} is not in the dictionary.')
62-
63-
word = word.upper()
64-
for letter in word:
65-
if letter not in draw:
66-
raise ValueError(f'{letter} is not in draw.')
67-
68-
return word
57+
draw_copy = draw.copy()
58+
print('Letters drawn:', *draw_copy)
59+
60+
while True:
61+
word = input('Form a valid word: ').lower()
62+
63+
try:
64+
if word not in DICTIONARY:
65+
raise ValueError(f'{word} is not in the dictionary. Try again.')
66+
67+
word = word.upper()
68+
for letter in word:
69+
if letter not in draw_copy:
70+
raise ValueError(f'{letter} is not in draw. Try again.')
71+
else:
72+
draw_copy.remove(letter)
73+
74+
return word
75+
except ValueError as e:
76+
print(e)
77+
continue
6978

7079

7180
def main():

0 commit comments

Comments
 (0)