[Solved] TypeError: unsupported operand type(s) for +=: ‘NoneType’ and ‘str’


You shouldn’t do total = None. NoneType cannot be used against addition.

There’s an extra problem suggested by the error message: From your description you’re trying to add 3 numbers, but the return type of the builtin input() is str. So this is what you’re supposed to write:

total = 0
for i in range(0, 3):
    num = input('Please enter number {}:'.format(str(i)))
    total += int(num)

All the points:

  • Indent the code correctly. Indentation is a crucial part of Python.
  • Don’t set total to zero at every loop. Only set it once outside the loop
  • Take care of types

2

solved TypeError: unsupported operand type(s) for +=: ‘NoneType’ and ‘str’