简体   繁体   English

python程序告诉没有长度功能的代码中的单词数量?错误是意外的.plzz告诉我哪里错了

[英]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.

相关问题 我正在编写将二进制数转换为十进制数的代码,这就是我所做的,有人可以告诉我哪里错了,(我进入 Python 1 个月 - I am making a code to turn a Binary number into decimal number, This is what I have done, Can someone tell where I am wrong, (i am 1 month into Python 有人可以告诉我这个 python 代码哪里错了吗? - Can someone please tell me where am I wrong in this python code? 我无法在Python中正确定义一个函数。 谁能告诉我我要去哪里错了? - I can't properly define a function in Python. Can anyone tell me where I am going wrong? Python 不断返回断言错误,但我不知道哪里出错了 - Python keeps returning an assertion error but I can’t tell where I went wrong 使用 for 循环计算从 1 到给定数字的所有数字的总和(也请告诉我哪里错了) - Calculate the sum of all numbers from 1 to a given number using for loop (Also pls tell me where i am wrong) 在 GOOGLE COLAB 中运行此 python 代码时,它向我显示错误。 谁能告诉我我做错了什么并分享更正的代码? - On running this python code in GOOGLE COLAB, it showing me error. Can anyone please tell what am i doing wrong and share a corrected code? 告诉我这个python代码有什么问题吗? - Tell me whats wrong with this python code? 有人可以告诉我为什么我收到意外的缩进错误吗? - Could somebody tell me why i am getting an unexpected indent error? 有人可以告诉我我的代码有什么问题吗? 我在调试时遇到问题 - Can someone tell me what is wrong with my code? I am having problems debugging 谁能告诉我我做错了什么,字典与 Python 中的列表? - Can anyone tell me what I am doing wrong, dictionary vs list in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM