use*_*517 9 python string input typeerror
编程新手并不确定我为什么会收到此错误
count=int(input ("How many donuts do you have?"))
if count <= 10:
print ("number of donuts: " ) +str(count)
else:
print ("Number of donuts: many")
Run Code Online (Sandbox Code Playgroud)
mgi*_*son 17
在python3中,print是一个返回的函数None.所以,行:
print ("number of donuts: " ) +str(count)
Run Code Online (Sandbox Code Playgroud)
你有None + str(count).
你可能想要的是使用字符串格式:
print ("Number of donuts: {}".format(count))
Run Code Online (Sandbox Code Playgroud)
您的括号位于错误的位置:
print ("number of donuts: " ) +str(count)
^
Run Code Online (Sandbox Code Playgroud)
把它移到这里:
print ("number of donuts: " + str(count))
^
Run Code Online (Sandbox Code Playgroud)
或者只使用逗号:
print("number of donuts:", count)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
55323 次 |
| 最近记录: |