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

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.

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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!

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

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!