I am coming from C# background and I have hard time figuring out how to run python script.
So, I wrote this simple recursive binary search and found online that I can do something like this:
def chop(array, search, lo, high):
if lo <= high:
middle = (high + lo) /2
if array[middle] == search:
return 'true'
elif search > array[middle]:
return chop(array, search, middle + 1, high)
else:
return chop(array, search, lo, middle -1)
return 'false'
if __name__ == '__main__':
a = [1,2,3,4,5,6,7,8,9,10]
print chop(a, 21, 0, len(a) -1)
the __main__ will be main my method to call the chop function from but it doesn't work. I have it saved in a test.py file. Also I though I can somehow run just the chop function from Python Shell, but I have no idea how to do it. Please advice. Thank you.
if __name__ == '__main__':.$ python myscript.py