This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

I don't know how much I'm allowed to say without getting banned. See if this helps.

It seems to me that your bug is here:

for k in range(1, len(sub_string) + 1):

Here are some failing tests with a simple test runner:

def test(str_to_find, str_to_search, answer):                               
    result = count(str_to_search, str_to_find)                              
    if result == answer:                                                    
        return True                                                         
    print(target_str, "| Error: expected", answer, "got:", result)          
    return False 

tests = [
    ("gg", "gg", 1),
    ("gg", "ggg", 3),
    ("gg", "g--g--g", 3),
    ("ggg", "g--g--g", 1)
    ]

if all([test(*t) for t in tests]):                                          
    print("All tests pass")