Summary: Function searches an array for a number, and if found it will return found, etc. The code works, it gives me the right response, but is this the proper way to set up an array, or is it searching a list? I am new to programming and I believe that an array is better (faster) not sure why tho?
array = [2, 3, 5, 7, 11, 13, 17, 19,
23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
targetValue = int(input())
def binarySearch(array, targetValue):
min = 0
max = len(array) - 1
found = 'Number is not in array'
while (min <= max):
middle = (min + max)/2
if array[middle] == targetValue:
found = 'We found the number in the array!'
return found
else:
if targetValue < array[middle]:
max = middle - 1
else:
min = middle + 1
return found
index = binarySearch(array, targetValue)
print (index)