Hello, I have been working on the topic of dictionaries in Python. During this project, though I have had to ask for advise:
I am struggling with the last three tasks.
I have setup the needed dictionaries, but I have encountered a TypeError, when running the code below:
for player, words in player_to_words.items(): player_points = 0 for word in words: player_points += (score_word(word)) #function defined earlier player_to_points[player] = player_points #creating new key:value pair print(player_to_points)
The python interpreter evaluated the above to:
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'
I therefore, “tried” to debug, by simple running:
for player, words in player_to_words.items(): player_points = 0 for word in words: print(score_word(word))
In this case, the interpreter returned something like:
6 None 12 None 11 None 8 None 7 None ...
I am puzzled, why it evaluates to
score_word looks like:
def score_word(word): point_total = 0 for letter in word: point_total += letters_to_points.get(letter, 0) print(point_total)
Why I would print
None, when scoring the words ?