Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

PS4 - Playing a Hand: Hello, I have a annoying situation with my code, mine in Idle works fine, and my totalScore variable, does not accumulate in every test, and to make it more annoying grader says my output is this: Current Hand: a d i k o n Enter word, or a "." to indicate that you are finished: daikon "daikon" earned 116 points. Total: 116 points Current Hand: *** Error: Your code called raw_input more times than necessary. Please review where you are using the raw_input function. Additionally also be sure your print statements match up with the sample output. But my output on I

OpenStudy (anonymous):

Bu my output on Idle is: playHand({'a': 1, 'd': 1, 'i': 1, 'k': 1, 'o': 1, 'n': 1}, wordList, 6) Current Hand: a d i k o n Enter word, or a "." to indicate that you are finished: daikon "daikon" earned 116 points. Total: 116 points Run out of letters. Total score: 116 points.

OpenStudy (anonymous):

The grader shows that I make again this code line: word = (raw_input('Enter word, or a "." to indicate that you are finished: ').lower()) My Idle does not show it.

OpenStudy (anonymous):

Should I include the other def I use on the code? I mean: isValidWord, getWordScore, updateHand. BTW I use a global variable totalScore, and totalScore = 0 is outside of def playHand(hand, wordList, n):

OpenStudy (turingtest):

I had the same problem at first, along with a few others. Try taking out the doc string for starters...

OpenStudy (anonymous):

What doc string? I don't understand. Btw I have a "totalEarned = 0" outside of the def playhand(....) and I use "global totalEarned" because when I call inside of playhand function to make it recursive "totalEarned" would be initialize to zero.

OpenStudy (turingtest):

the doc string is the thing that is in quotes in red before your code on the edX site

OpenStudy (anonymous):

Ow ok, in the grader is like this: totalEarned = 0 def playHand(hand, wordList, n): """ """ earned = 0 global totalEarned

OpenStudy (turingtest):

yeah take out the '''' '''' stuff also you should really not need a global variable like that, especially for the edX grader which is not integrated into your IDLE

OpenStudy (turingtest):

nothing should be before your definition on the grader though

OpenStudy (turingtest):

I will just tell you that mine only has HAND_SIZE as defined before the code, yet it is still after the definition def playGame(wordList): i=0 n=HAND_SIZE <code> the variable i I just used for the replay part, you can ignore that my point is that I really don't think you should have any global variables, or anything before def playGame

OpenStudy (anonymous):

well actually I put it outside of the function. But when my code reach this section: earned = getWordScore(word,n) totalEarned += earned print '"'+word+'"' + ' earned', earned,'points. Total:' , totalEarned , 'points' print '' hand = updateHand(hand, word) return playHand(hand, wordList, n) I use return playHand(...) and that's when totalEarned becomes zero, if I initilize it (totalEarned = 0) inside of def playHand(...)

OpenStudy (turingtest):

well mine is not recursive also I was confused, I thought we were looking at playGame, not playHand, but still, no global variables or assignments before the definition should be necessary. instead of a recursive call I used a while loop, I will show you my first couple assignments: def playHand(hand, wordList, n): n=calculateHandlen(hand) totalScore=0 while... <code> so I needed no assignments before def playHand, nor global variables.

OpenStudy (anonymous):

I started like that, I didn't like to deal that when I reach -inside of while loop- if is not a valid word ... what next? a while inside of a while, to keep asking for a valid word, and I didn't like it to do that.

OpenStudy (anonymous):

But let me tell you, on Idle it works perfectly xD

OpenStudy (turingtest):

Oh I believe you, the grader on this is picky, I had the same error message as you at first It worked with pseudocode something like #while the hand is not empty, continue #display hand, ask for raw input #if the word is the '.', break out of program # if the word is valid, get score etc. #if the word is not valid, tell the user so this way the program runs until there are either no more letters, or the user presses '.' no recursion necessary.

OpenStudy (anonymous):

yeah I got you, I've never seen it so capricious, I'll make it again, and now using the pseudocode, the last time I erased it all xD thanks!

OpenStudy (anonymous):

Yeah that easy xD just 3 minutes and just have to correct this: playHand({'a': 2, 'p': 1, 'r': 1, 'e': 2, 't': 1}, wordList, 7) pear = 24 points tea = 59 points (should be only 9 but I use the whole word) It's a bug?? I've never play scrabbel

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!