3

I really do not understand, why the code

def isIn(char, aStr): 
    ms = len(aStr)/2
    if aStr[ms] == char:
        print 'i am here now'
        return True
    elif char>aStr[ms] and not ms == len(aStr)-1:
        aStr = aStr[ms+1:]
    elif char <aStr[ms] and not ms == 0:
        aStr = aStr[0:ms]
    else:
        return False
    isIn(char, aStr)

print isIn('a', 'ab')

does keep on returning None. it prints 'i am here now', but it does not return True, just as the next line says. Why?

HeinzKurt
  • 612
  • 9
  • 18
  • Maybe a `return isIn(char, aStr)` for the last line of the function? Right now it's falling off the end of the function without returning anything. – Joachim Isaksson Mar 10 '14 at 21:15

1 Answers1

6

You probably want a return on the last line:

return isIn(char, aStr)

Without it, the function simply returns None when it terminates without seeing a return.

arshajii
  • 127,459
  • 24
  • 238
  • 287