Facebook
From Albert , 1 Year ago, written in Plain Text.
This paste is a reply to Array search from Albert C Dominic - go back
Embed
Viewing differences between Array search and Re: Array search
def search_element(arr, element):
    for i in range(len(arr)):
        if arr[i] == element:
            return i
    return -1

# Example usage
my_array = [10, 20, 30, 40, 50]
element_to_search = 30

result = search_element(my_array, element_to_search)

if result != -1:
    print(f"The print(f"The element {element_to_search} is found at index {result}.")
")
else:
    print(f"The print(f"The element {element_to_search} is not present in the array.")")