No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.py 772B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python3
  2. import time
  3. x = [i for i in range(10)]
  4. y = [i for i in range(100,110)]
  5. z = sorted([1,3,5,6,8,3,3,5,5,77,9,7,4,333,34])
  6. def search(inp, array):
  7. minimum = array[0]
  8. maximum = array[-1]
  9. step = 1
  10. while True:
  11. if minimum > inp or maximum < inp:
  12. return -1, -1
  13. index = round((inp - minimum)/(maximum - minimum)*len(array))
  14. print(index, array[index])
  15. time.sleep(.25)
  16. if array[index] == inp:
  17. return index, step
  18. elif array[index] < inp:
  19. minimum = array[index]
  20. elif array[index] > inp:
  21. maximum = array[index]
  22. elif minimum == array[index]:
  23. index += 1
  24. step += 1
  25. print(z)
  26. print(search(8, z))