提供以下Python代码的完整版本。


def binary_search(arr, x):
'''在已排序的数组中执行二分查找算法。'''

low = 0
high = len(arr) - 1
mid = 0

while low <= high:
mid = (low + high) // 2
if arr[mid] < x:
low = mid + 1
elif arr[mid] > x:
high = mid - 1
else:
return mid

return -1
Here is the full version of the Python code for binary search algorithm:

```python
def binary_search(arr, x):
    '''Perform binary search algorithm on a sorted array.'''

    low = 0
    high = len(arr) - 1
    mid = 0

    while low <= high:
        mid = (low + high) // 2
        if arr[mid] < x:
            low = mid + 1
        elif arr[mid] > x:
            high = mid - 1
        else:
            return mid

    return -1
```