I'm trying to write a program to see how many times a 3-digit substring shows up in a string. For example, the substring "122" would show up in the string "122122" 2 times. However, whenever I run it, it returns 0, even if the substring does actually show up. Can you tell me what's wrong with my function?
def count_substring(string, sub_string):
count = 0
for i in range (len(string)):
if string[i:i+3] == sub_string:
count+=1
returnin your function?None. You gottareturn countat the end!countfunction. Try"122122".count("122")!