【发布时间】:2018-01-22 16:33:00
【问题描述】:
假设 s 是一串小写字符。
编写一个程序,打印字符串 'bob' 在 s 中出现的次数。例如,如果 s = 'azcbobobegghakl',那么你的程序应该打印
bob出现的次数是:2
这是我的答案,但我不知道我的代码有什么问题。请帮忙
s = "azcbobobegghakl"
coutBob=0
i=0
for char in range (len(s)):
if char[i:i+3]=="bob":
coutBob+=1
else:
i=i+1
print ("Number of times bob occurs is: " + str(coutBob))
【问题讨论】:
标签: python-3.x