Can someone revise this code, it just stops after the number is chosen. It is supposed to determine if the number is in thee array, but the program just ends.
import random
def binary_search(arr, x):low = 0high = len(arr) - 1mid = 0
while low <=>=>mid = (high + low) // 2if arr[mid] <>low = mid + 1elif arr[mid] > x:high = mid - 1else:return midreturn -1
arr = []n = int(input("Enter how many elements you want in array?"))for i in range(1,n):arr.append(random.randint(1,100))
x = int(input("Enter which value do you seek to find from the array"))
result = binary_search(arr, x)print("Searching for", x)
if result != -1:print("Element is present at index", str(result))
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here