I'm using Python to search for the position of an entered name in a list. I use the binary search: compare entered name with the middle-value of the list, if not matched, search in the 1st half list then 2nd half list. When I run following script, IDE shows nothing. Please help me review it:
def search_for_name(name, list):
midValue = list[int(len(list)/2)]
x = 0
if name == midValue:
x = int(len(list)/2)
return x
elif name < midValue:
while x < int(len(list))/2:
if list[x] == name:
return x
else:
x += 1
else:
x = int(len(list)/2)
while x <= int(len(list)):
if list[x] == name:
return x
else:
x += 1
print('The name you want to search exists in our list. Its position is {}'.format(x))