fork download
  1. import random
  2.  
  3. def create_array(number_of_elements: int = 50) -> list:
  4. arr = []
  5. for _ in range(number_of_elements):
  6. arr.append(random.randint(1, 100))
  7. return arr
  8.  
  9. def find_element(list, needle: int):
  10. list_copy = list.copy()
  11. list_copy.append(needle)
  12. watcher_index = len(list_copy) - 1
  13. for i in range(len(list_copy)):
  14. if list_copy[i] == needle and i != watcher_index:
  15. return i
  16.  
  17. return None
  18.  
  19. array_of_elements = create_array(50)
  20. element_to_find = int(input("Wprowadź element do wyszukania: "))
  21. element_position = find_element(array_of_elements, element_to_find)
  22. print("Przeszukiwana tablica: ")
  23. print(array_of_elements)
  24. if element_position is None:
  25. print("Szukanego elementu nie ma w tej tablicy.")
  26. else:
  27. print(f"Szukany element znajduje się w tablicy po raz pierwszy na pozycji {element_position}.")
  28.  
Success #stdin #stdout 0.03s 9980KB
stdin
12
stdout
Wprowadź element do wyszukania: Przeszukiwana tablica: 
[73, 93, 33, 78, 73, 20, 86, 13, 44, 16, 44, 81, 46, 22, 7, 79, 99, 52, 30, 33, 42, 22, 19, 94, 44, 33, 4, 71, 86, 70, 31, 79, 87, 53, 26, 15, 92, 94, 4, 9, 59, 83, 13, 7, 22, 27, 48, 80, 23, 85]
Szukanego elementu nie ma w tej tablicy.