Python程序计算代码中的字数而不使用长度函数?错误是意外的。请告诉我错在哪里。

2024-04-25 03:57:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我从一小时前就开始尝试这段代码,它的输出真的出乎意料

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)

Tags: oftheno代码innumberaddedfor