Q:

why the output is not good in some cases?

i feel stupid and don't know why the output is not good in some cases.
here is the output (at the end)
it sould find the first sub string in given string for example:
sim('banan','na') -> 'na'
 def rev (str):
    rev_str=''
    i =  len(str)-1;
    while (i >= 0):
        rev_str += str[i];
        i = i-1;
  return rev_str;
  ######################################
 def sim (str,sub):
   sub_len = len (sub);
   start = str.index(sub);
   rev_str = rev(str)
   rev_sub = rev(sub)

if (start ==0):
    start =1;

end = start + rev_str.index(rev_sub,start-1);

ret_val = ''
print start , end
for n in range (start,end):
    ret_val += str[n];

return ret_val;

            print sim('abcdef', 'abc')
            print sim('abcdef', 'bc')
            print sim('banana', 'na')

the output : 
        1 4
        bcd
        1 4
        bcd
        2 4
        na

A:

def sim(haystack, needle):
    if needle in haystack:
        return needle

If you want indices:
def sim(haystack, needle):
    index = haystack.index(needle) # throws ValueError when not found
    return (index, index + len(needle))

