Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# a list of numbers to search through:
number_list = [1]
# the number we want to search for:
target_number = 1
# the "index" (position number) of the first element in the list
# counting starts at zero instead of 1:
start = 0
# the index of the last element in the list:
end = len(number_list) - 1
# a way of tracking if we found the number or not:
found_number = False

print('hih')

# "binary search" of the list for the number:
while start <= end:
    mid = int((start + end) / 2)
    print(mid)
    if target_number < number_list[mid]:
        end = mid -1
    elif target_number > number_list[mid]:
        start = mid + 1
    else:
        found_number = True
        break

# print to the shell whether we found the number
if found_number == True:
    print("Found the number!")
else:
    print("Number not found.")