A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

I'm I loosing it? I'm on Prob Set 4.1 and I believe the solution is quite straighforward, but I am confused on something on the result I'm getting.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    my code is : def get_word_score(word, n): score = 0 if len(word) == n: score += 50 for letter in word: print letter score += SCRABBLE_LETTER_VALUES[letter] print score

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

    with get_word_score('waybill', 7) as my input, I get an output of: w 54 a 55 y 59 b 62 i 63 l 64 l 65 Shouldn't I just get the last score of 65 since the print statement is outside of the for loop? If I indent the print score statement to be on the same indentation as the print letter I get an unexpected indent error. I am confused!

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I realized I posted the wrong code above. It should be: def get_word_score(word, n): score = 0 if len(word) == n: score += 50 for letter in word: print letter score += SCRABBLE_LETTER_VALUES[letter] print score

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, but get_word_score needs to return the score, not print it.

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the reply! I know it's to return rather than print score, I just wanted to make sure it was the correct value. To solve my issue I had to manually retype the function for it to work. Very odd. Some voodoo going on :)

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You might have had a tab issue. I've had a piece of code that looks correct, but I had to entirely retab it because somewhere a space was messing up the entire code.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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.