Я просмотрел ваш код и запустился в моей системе.Каждый раз, когда размер вашего списка уменьшается и в конце он становится равным 0. В тот момент, когда ваш код вычисляет строку mid_element = list_nums[int(len(list_nums)/2)-1]
, ответом будет -1, что выходит за пределы диапазона.
Я проследил коди вывод будет следующим:
Helllo user, select a number from 1-100 in your mind and i will try to guess it...
Length of list_num: 100
Is your selected number 50
is it too high or too low..? : too high
Length of list_num: 49
Is your selected number 25
is it too high or too low..? : too high
Length of list_num: 23
Is your selected number 13
is it too high or too low..? : too high
Length of list_num: 10
Is your selected number 8
is it too high or too low..? : too high
Length of list_num: 4
Is your selected number 6
is it too high or too low..? : too high
Length of list_num: 1
Is your selected number 6
is it too high or too low..? : too high
Invalid entry..Try again
Length of list_num: 0
Так что внесите изменения, приведенные в ответе выше.