A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

Hi, In ps5 problem 2 when I run update_hand manually it returns the right answer but when I run the test it returns none. Any idea why this happens? Here is my code for update_hand: for i in range (0, len(word)): used = word[i] if hand[used] >= 0: hand[used] = hand[used] - 1 return hand

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

    1) you probably want to use codepad.org to create links to your code 2) I can't tell why without the code for 'test'

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The code for test_update_hand, http://codepad.org/hPApKb1R

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    could you please explain to me how you are able to access the words.txt file. When I use WORDLIST_FILENAME = open ("words.txt") I get the following error code inFile = open(WORDLIST_FILENAME, 'r', 0) TypeError: coercing to Unicode: need string or buffer, file found

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It should be WORDLIST_FILENAME = "words.txt" The error you're getting is because you have open("words.txt").

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what are you trying to accomplish here? expected_hand2 = {'a':0, 'q':0, 'l':1, 'm':1, 'u':0, 'i':0} if hand2 != expected_hand1 and hand2 != expected_hand2: here's what I think is happening. your program works. hand2 is updated correctly. hand2 = {'a':0, 'q':0, 'l':1, 'm':1, 'u':0, 'i':0} then you have IF NOT EQUAL but hand2 and expected_hand2 are equal, so your if statement doesn't run.

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    by here, I mean these 2 lines of codes expected_hand2 = {'a':0, 'q':0, 'l':1, 'm':1, 'u':0, 'i':0} if hand2 != expected_hand1 and hand2 != expected_hand2:

  7. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    looks like it works to me http://codepad.org/JJGkZKMJ

  8. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    check to see what the values for the letters are before you start, then either keep it in the dictonary or delete it. for letter in word: numberofletters=hand.get(letter,0) if numberofletters==0: return word,'cannot be spelled from this hand' if numberofletters==1: del hand[letter] if numberofletters>1: hand[letter]=hand[letter]-1 return hand

  9. 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

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.