Start free

Beginner · Lists · 105 of 264

Find a number

Find where a number first appears in a list. Positions start at 0.

Input: whole numbers on one line, then the number to find on the next line. Output: found at <position>, or not found

Examples

Input
4 8 15 16 23 42
15
Output
found at 2
Input
1 2 3
7
Output
not found
Input
5 5 5
5
Output
found at 0

One more test checks other inputs when you press Check.

Stuck? The idea behind lists

A list keeps several values in order: [3, 9, 1]. Its items are numbered from 0, like a string's characters.

append() adds to the end; sum(), min(), max(), len() and sorted() work on a whole list. Read numbers from one line with input().split() and int().

numbers = [int(x) for x in input().split()]
print(sum(numbers), max(numbers))
numbers.append(0)
print(numbers)

Watch for: split() gives text: "10" sorts before "9". Turn each item into a number before comparing or adding.

All the lists exercises
Your code
Opening the code editor…
Python 3.14 in your browser
Output
Run shows what your program prints. Check tests it on every example and the hidden tests.

More lists exercises