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.
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
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!
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
Yes, but get_word_score needs to return the score, not print it.
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 :)
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.
Join our real-time social learning platform and learn together with your friends!