How to fix "TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'"?

user2101517 picture user2101517 · Feb 23, 2013 · Viewed 74.1k times · Source

I am unsure why I am getting this error

count=int(input ("How many donuts do you have?"))
if count <= 10:
    print ("number of donuts: " ) +str(count)
else:
    print ("Number of donuts: many")

Answer

mgilson picture mgilson · Feb 23, 2013

In python3, print is a function that returns None. So, the line:

print ("number of donuts: " ) +str(count)

you have None + str(count).

What you probably want is to use string formatting:

print ("Number of donuts: {}".format(count))