我不确定为什么会出现此错误
count=int(input ("How many donuts do you have?"))
if count <= 10:
print ("number of donuts: " ) +str(count)
else:
print ("Number of donuts: many")
在python3中,
print
是一个返回None
的函数。 所以,这一行:
print ("number of donuts: " ) +str(count)
你有
None + str(count)
。
您可能想要的是使用字符串格式:
print ("Number of donuts: {}".format(count))
你的括号位置错误:
print ("number of donuts: " ) +str(count)
^
移到这里:
print ("number of donuts: " + str(count))
^
或者只使用逗号:
print("number of donuts:", count)
现在,使用 python3,您可以使用
f-Strings
,例如:
print(f"number of donuts: {count}")
在 Python 3 中,print 不再是一个语句。你想做的事,
print( "number of donuts: " + str(count) )
而不是添加到 print() 返回值(即 None)
在python3中你可以使用这个
count=int(input("你有多少个甜甜圈?")) 如果数<= 10: print ("number of donuts: ", count) #print ("Number of donuts: {}".format(count)) #print(f"number of donuts: {count}") # you can use any of the above 3 statements to solve your problem else: print ("Number of donuts: many")