【问题标题】:Count words with the letter 'w' in them but only the(almost done) [duplicate]计算带有字母“w”的单词,但只计算(几乎完成)[重复]
【发布时间】:2019-03-27 20:51:14
【问题描述】:

所以目标是用字母“w”计算句子中单词的数量,我已经编写了计算 w 数量的代码,但我无法计算总单词数。

items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]
items = str(items)
acc_num = 0
for i in items:
    if i in ['w']:
        acc_num += 1
print(items)

【问题讨论】:

  • 删除items = str(items)
  • 输出变为0
  • 好的,让我详细说明...在您删除 items = str(items) 后,单击我链接的问题,阅读它,然后将解决方案应用于您的代码。

标签: python


【解决方案1】:

只需检查单词中是否包含字母 w。

items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]

count = 0
for i in items:
    if "w" in i:
        count +=1

【讨论】:

  • 谢谢!现在可以使用了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-19
  • 1970-01-01
  • 2021-07-30
相关资源
最近更新 更多