Python Dictionaries - Adding values

Hello, I have been working on the topic of dictionaries in Python. During this project, though I have had to ask for advise:
https://www.codecademy.com/paths/build-chatbots-with-python/tracks/python-3-data-structures-and-loops/modules/learn-python3-dictionaries/projects/scrabble

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 None.

The function 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 ?

Thanks, Michael.

None is the absence of a return value, looking at your score_word, I don’t see anything returned.

1 Like

Yes, of course you are right !! Apologies for spaming. I have changed the score_word function and I get the required output, meaning no None. Thank you also for your swift answer ! Thanks, Michael.

you didn’t spam, no need to apologize.

you’re welcome :slight_smile: