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
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'
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
It should be WORDLIST_FILENAME = "words.txt" The error you're getting is because you have open("words.txt").
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.
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:
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
Join our real-time social learning platform and learn together with your friends!