Find a string

  • + 0 comments

    Ya'll answers are complicated. I still used it for reference and this is what I came up with.

    def count_substring(string, sub_string): counter = 0

    for i in range(1, len(string)):
        if sub_string in string:
            find = string.find(sub_string)
            string = string[find + 1:]
            counter += 1
    return counter
    

    if name == 'main': string = input().strip() sub_string = input().strip()

    count = count_substring(string, sub_string)
    print(count)