import random def create_array(number_of_elements: int = 50) -> list: arr = [] for _ in range(number_of_elements): arr.append(random.randint(1, 100)) return arr def find_element(list, needle: int): list_copy = list.copy() list_copy.append(needle) watcher_index = len(list_copy) - 1 for i in range(len(list_copy)): if list_copy[i] == needle and i != watcher_index: return i return None array_of_elements = create_array(50) element_to_find = int(input("Wprowadź element do wyszukania: ")) element_position = find_element(array_of_elements, element_to_find) print("Przeszukiwana tablica: ") print(array_of_elements) if element_position is None: print("Szukanego elementu nie ma w tej tablicy.") else: print(f"Szukany element znajduje się w tablicy po raz pierwszy na pozycji {element_position}.")
12
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.