Sep-02-2017, 07:56 AM
(Sep-02-2017, 07:00 AM)rajeev1729 Wrote: please help me. i am unable to understand IndexError.
mid = first+last//2
You are getting that error due to logical a mistake. Read about the order of operation and operator precedence here.
Here's how this expression will be evaluated in python:
1-
last
is divided by 2 and only integer(//) is stored.2- result from above step is added to
first
and stored in mid
.what you want is:
mid = (first+last)//2