Advertisement
k1alo

Search

Dec 14th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def sequential_search(arr, target):
  2.     for i in range(len(arr)):
  3.         if arr[i] == target:
  4.             return i
  5.     return -1
  6.  
  7. array = ["apple", "banana", "cherry", "date", "elderberry"]
  8. target = "cherry"
  9.  
  10. result = sequential_search(array, target)
  11. if result != -1:
  12.     print(f"Элемент {target} найден в массиве на позиции {result}.")
  13. else:
  14.     print(f"Элемент {target} не найден в массиве.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement