anonymous
  • 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
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
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.
anonymous
  • 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.
anonymous
  • 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):

Looking for something else?

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

More answers

TuringTest
  • TuringTest
I had the same problem at first, along with a few others. Try taking out the doc string for starters...
anonymous
  • 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.
TuringTest
  • TuringTest
the doc string is the thing that is in quotes in red before your code on the edX site
anonymous
  • anonymous
Ow ok, in the grader is like this: totalEarned = 0 def playHand(hand, wordList, n): """ """ earned = 0 global totalEarned
TuringTest
  • 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
TuringTest
  • TuringTest
nothing should be before your definition on the grader though
TuringTest
  • 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 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
anonymous
  • 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(...)
TuringTest
  • 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... so I needed no assignments before def playHand, nor global variables.
anonymous
  • 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.
anonymous
  • anonymous
But let me tell you, on Idle it works perfectly xD
TuringTest
  • 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.
anonymous
  • 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!
anonymous
  • 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

Looking for something else?

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