Linear Search with Enumerate

Viewed 17

I have started learning Python not to long ago and have decided to try making a linear search algorithim. The problem that seems to exist is that found is never = true therefore never triggering the print. The program is attached below. Any help would be greatly appreciated!

numbers = [55,37,12,13,89,47,3,24,21]

number_to_find = input("Enter a number to find:")

found = False

for index, single_num in enumerate(numbers):

if numbers[index] == number_to_find: found = True

break

if found == True:

print(f"Found {number_to_find} at index {index}")

else: print(f"Unable to find {number_to_find} in array")

0 Answers
Related