Okay, don't laugh. I'm very new to python. Actually to programming all together. I'm doing an exercise where i have to count the number of a string in a word. Ex: count("is", "Mississippi") would be 2. I tried using string.find and was having no luck. So i tried to go back to the basics and use count. I can get it to pass 3/5 of the doctests. This is where i'm at:
def count(sub, s):
"""
>>> count('is', 'Mississippi')
2
>>> count('an', 'banana')
2
>>> count('ana', 'banana')
2
>>> count('nana', 'banana')
1
>>> count('nanan', 'banana')
0
"""
count = 0
if sub in s:
count += 1
print count
if __name__ == '__main__':
import doctest
doctest.testmod()
Any help would be greatly appreciated.