title: How to compute the number of steps in binary search?
body: <p>This code returns only the position of the target.
  I need to compute number of steps also.
  How can I modify this code to achieve my goal?</p>
  <pre><code>def binary_search(arr, low, high, x):
      if high &gt;= low:
          mid = (high + low) // 2
          if arr[mid] == x:
              return mid
  
          elif arr[mid] &gt; x:
              return binary_search(arr, low, mid - 1, x)
  
          else:
              return binary_search(arr, mid + 1, high, x)
  
      else:
          return -1
      
  LT = [1,2,3,4,5,6,7,8,9,10]
  pos = binary_search(LT,0,9,5)
  print(str(pos))
  </code></pre>