<p>我的老师要求我找到一种方法来计算单词“bob”在没有<code>str.count()</code>的任何随机字符串变量中的出现次数。所以我做了</p>
<pre><code>a = "dfjgnsdfgnbobobeob bob"
compteurDeBob = 0
for i in range (len(a) - 1):
if a[i] == "b":
if a[i+1] == "o":
if a[i+2] == "b":
compteurDeBob += 1
print(compteurDeBob)
</code></pre>
<p>但我想找到一种方法来做到这一点与任何长度的字如下所示,但我不知道如何做到这一点。。。你知道吗</p>
<pre><code>a = input("random string: ")
word = input("Wanted word: ")
compteurDeBob = 0
for i in range (len(a)-1):
#... i don't know...
print(compteurDeBob)
</code></pre>