Advertisement
KaySawbridge

Linear search using for

Aug 2nd, 2020
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. sequence=[2,1,3,4,5,3,5,6]
  2.  
  3. n = int(input("Which number are you looking for? "))
  4. position = 0
  5.  
  6. def search(sequence,n):
  7.  
  8.     for position in range(len(sequence)):
  9.         if n == sequence[position]:
  10.             print(sequence[position], "is at position", str(position))
  11.             position +=1
  12.     return n
  13.  
  14. search(sequence,n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement