Tom_Jung

Untitled

Feb 5th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import random
  2. numbers =[random.randint(1,30) for x in range(1,21)]
  3. alist = sorted(numbers)
  4. print(alist)
  5.  
  6. def linear_search(alist, value):
  7.  
  8. for position, item in enumerate(alist):
  9.  
  10. if item == value:
  11. print(item, 'is in position', str(position))
  12. break
  13.  
  14. if item > value:
  15. print('item is not found in alist')
  16. break
  17.  
  18.  
  19. linear_search(alist, 9)
Advertisement
Add Comment
Please, Sign In to add comment