anonymous
  • anonymous
PS5, problem 3... I'm so close! The problem I am having is when I call the update_hand function in is_valid_word I get an error when it's checking for # test 4 hand = {'r': 1, 'a': 3, 'p': 2, 't': 1, 'u':2} word = "honey" The criteria for update_hand explicitly states that we are to assume that 'hand' has all the letters in word. Therefore it passes when testing the update_hand function. If I delete this from the test_ps5.py file, it runs successfully.
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Here's my code for update_hand and is_valid_word. Any tips are greatly appreciated! def update_hand(hand, word): new_hand = hand for letter in word: new_hand[letter] = new_hand[letter] -1 return new_hand def is_valid_word(word, hand, word_list): test_hand = update_hand(hand, word) for letter in word: if test_hand.get(letter,0) < 0: return False match_found = False i = 0 while match_found == False and i < len(word_list): if word == word_list[i]: match_found = True break else: i += 1 return match_found
anonymous
  • anonymous
Your version of is_valid_word is fine, your version of update_hand will raise KeyError when it's given a word that's not composable with the letters in the hand. You'll need to do something like the statement below to prevent the errors in the 'honey' test. new_hand[letter] = new_hand.get(letter,0) -1 Also your update_hand function mutates the hand it's given (which you don't want to do). Be sure to make a copy of it, don't just give the same dictionary a new name.
anonymous
  • anonymous
Thanks for the tip :)

Looking for something else?

Not the answer you are looking for? Search for more explanations.