fork download
  1. def bisect(l, val):
  2. '''
  3. lookins value in given list
  4. returns true, if value is in
  5. False otherwise
  6. '''
  7. low = 0
  8. high = len(l) - 1
  9. while low <= high:
  10. mid = (low + high) // 2
  11.  
  12. if l[mid] == val:
  13. return True
  14. elif l[mid] < val:
  15. low = mid + 1
  16. elif l[mid] > val:
  17. high = mid - 1
  18. return False
  19.  
  20. l = [random.randint(1, 200) for x in range(1, 100)]
  21.  
  22. print(l)
  23.  
  24. print('Lets bisect! Lookong for 10', bisect(l, 10))# your code goes here
Runtime error #stdin #stdout #stderr 0.02s 27712KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 20, in <module>
  File "./prog.py", line 20, in <listcomp>
NameError: name 'random' is not defined