I have to define a function called letterCount in which it returns an integer for the number of times there is a string in the function. For some reason, it returns 2 and I am supposed to return 7
def letterCount(text,collection):
for collection in text:
if collection in text:
return len(collection) + 1
seuss = 'The cat in a hat came back'
letters = 'ac'
print(letterCount(seuss,letters))
returnanything at all.for collection in text...if collection in textis kind of redundant.collectionin your function. You start off withcollectionbeing "ac" but then, when you do yourforloop, collection becomes "T" (i.e. the first letter in your sentence).