[英]python program to tell the number of words in code without length function?the error is unexpected .plzz tell where i am wrong
i've been trying this code from 1 hour and its output coming out is really unexpected. 我从1小时开始尝试这段代码,它的输出结果确实出乎意料。
var=input('sentence')
no=1
for i in var:
if i==" ": #i've added a space as the number of words will be the number of spaces in a sentence
no+=1
print(no)
You forgot the : at the end of your if statement. 您在if语句末尾忘记了:。 The following should work:
以下应该工作:
var=input('sentence')
no=1
for i in var:
if i==" ":
no+=1
print(no)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.