我在输出中得到错误的数字

时间:2017-09-07 10:02:13

标签: python

在此代码中,程序计算bob的名称在字符串s

中的次数
s = 'tobooboboboboboobooxbobbs'
count = 0
for name in "bob":
    if name in s:
        count += s.count(name)
print("Number of times bob occurs is: " + str(count)) 

我希望看到这样的输出:

Number of times 'bob' occurs is: 5

但我得到了:

Number of times bob occurs is: 32

为什么呢?我如何解决它?点的平均值是什么:.中的s.count(name)

0 个答案:

没有答案