Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Gianko15 Group Title

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

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  2. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  3. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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):

    • 2 years ago
  4. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  5. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  6. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
  7. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  8. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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

    • 2 years ago
  9. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    nothing should be before your definition on the grader though

    • 2 years ago
  10. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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

    • 2 years ago
  11. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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(...)

    • 2 years ago
  12. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  13. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  14. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  15. TuringTest Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  16. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

    • 2 years ago
  17. Gianko15 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • 2 years ago
    • Attachments:

See more questions >>>

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.