Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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")
like image 508
user2101517 Avatar asked Feb 23 '13 03:02

user2101517


2 Answers

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))
like image 70
mgilson Avatar answered Oct 04 '22 07:10

mgilson


Your parenthesis is in the wrong spot:

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

Move it here:

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

Or just use a comma:

print("number of donuts:", count)
like image 44
Blender Avatar answered Oct 04 '22 07:10

Blender