Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

LoveMathFermat

  • 3 years ago

Hi! Could you guys look at my code for problem #2: Update a hand in a word game. def update_hand(hand, word): for letters in word: hand[letters]=hand[letters]-1 return hand This code doesn't work for some cases. For instance, I have {s e e a} in my hand and I typed 'sea' which also deletes extra 'e' that I had. Can you guys explain what I am thinking wrong conceptually and how it should be fixed? Thank you!

  • This Question is Closed
  1. TuringTest
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I have the almost exact same code as you for that problem, so perhaps your bug lies in another function. The only difference is that I clone the hand for the replay part later on. newHand=hand.copy() but I don't think that should cause the effect you are dealing with.

  2. rsmith6559
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    For debugging, try printing hand as part of each iteration. Dollar says it's not what you expect.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy