I am trying to do the function count without using count() it is working and everything okay but when I try to search two letters in one word its returning 0. When I try to search 1 word in a letter its working normal.
def count(str, sub):
found = 0
for key in str:
if key == sub:
found += 1
return found
str = input("Enter a string: ") #or we can initialize a string
sub = input("Enter a substring: ") #or we can initialize a substring
count(str, sub)
print ("letter: ", sub)
print ("count: ", count(str, sub))
for key in str:will always go one letter at a time, so you can not use existing logic to search for two characters at a time.print('bctestbc'.count('bc'))to return2