Linear Search

Advanced

In this challenge, we're going on a hunt, but not just any hunt! We're going to find a treasure hidden in a list using a technique called Linear Search.

Imagine you have a line of chests, and each chest has a number. Someone tells you to find a particular chest with a special number. You start from the first chest and check each one, in order, until you find the chest you're looking for.

Your task is to write a function named linear_search, which will help us find the hidden treasure (or the right number) in the list. If you find the treasure, return the position (index) of the chest; however, if it's not there, return -1.

Here's how you can create your treasure-hunting function:

linear_search([1, 3, 5, 7, 9], 5) # returns 2 linear_search([0, 22, 34, 49], 49) # returns 3 linear_search([4, 1, 0], 8) # returns -1 (not found)

Help us find the treasure and become the greatest searcher of all time!

Geek
Inputs

Arg 1:

[1,3,5,7,9]

Arg 2:

5
Expected Output
2
Actual Output
Linear Search [advanced] | Coding for Kids