Skip to content

Commit 05f854f

Browse files
fix to correct the typecast
TypeError Traceback (most recent call last) <ipython-input-7-6e7ff2ec5466> in <module> 27 28 # Function call ---> 29 result = binarySearch(arr, 0, len(arr) - 1, x) 30 31 #printing the output <ipython-input-7-6e7ff2ec5466> in binarySearch(arr, l, r, x) 4 mid = l + (r - l) / 2; 5 ----> 6 if arr[mid] == x: 7 return mid 8 TypeError: list indices must be integers or slices, not float
1 parent 75d35e4 commit 05f854f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Binary_search.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
def binarySearch(arr, l, r, x):
44
while l <= r:
55

6-
mid = l + (r - l) / 2; #extracting the middle element from the array
6+
mid = l + (r - l) / 2 #extracting the middle element from the array
7+
mid=int(mid) #it has to be integer
78

89
# Check if x is present at mid
910
if arr[mid] == x:

0 commit comments

Comments
 (0)