Classic algorithms · 7 / 22 Exercise Easy

Linear search

Objective

Create a Python program that looks for a number in a list by going through it from start to end (linear search).

Instructions

  • Read a line with integers separated by spaces and, on the next line, the number to look for.
  • Go through the list with a loop and stop at the first position where it appears. Positions start at 0. Do not use index() or in.
  • If you find it, show Found at position P. Otherwise, show Not found.
Input
4 8 15 16 23 42
16
Output
Found at position 3

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise