In the text editor, you will find the code for the linear_search() function that we implemented in Python.

When called, our function returns either an index of an element that matches the target value or a ValueError express that the value was not found.

The text editor includes the code for the linear_search() function, a list of numbers called number_list and a variable called target_number, which stores target value that we will be searching for in number_list.

Let’s practice calling linear_search() and explore the return values for different calls to the function.



We’re searching for 33.

Call linear_search() to find whether the target_number is in number_list and set this to the variable result.

Print result.


We won’t always find what we’re looking for.

Within the try block provided, search for 100 to see what happens when a value is not found in the list.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?