File tree Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -54,18 +54,27 @@ def draw_letters():
5454
5555def 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
7180def main ():
You can’t perform that action at this time.
0 commit comments