anonymous
  • anonymous
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
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.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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'
anonymous
  • anonymous
The code for test_update_hand, http://codepad.org/hPApKb1R
anonymous
  • anonymous
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

Looking for something else?

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

More answers

anonymous
  • anonymous
It should be WORDLIST_FILENAME = "words.txt" The error you're getting is because you have open("words.txt").
anonymous
  • anonymous
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.
anonymous
  • anonymous
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:
anonymous
  • anonymous
looks like it works to me http://codepad.org/JJGkZKMJ
anonymous
  • anonymous
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

Looking for something else?

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