I have to write a code substrn, which takes string arguments sup and sub, and returns the integer count of the (possibly overlapping) number of times sub can be found in sup.
I wrote this code
def substrn(sup,sub):
   if sub in sup:
      x = 0
      for i in sup:
         if sub in sup[sup.index(i):(int(len(sub))+int(sup.index(i)))]:
            x = x +1 
      return x 
   else:
      return 0
print(substrn("wooloomooloo", "oo"))
print(substrn("wablabmablab", "ab"))
Can anyone help me understand what went wrong with my code and how I can change it? My first print statement produced 8 but my second print statement produced 4, they should be the same.
 
    