Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 9

A programmer has written a Python program to search for a specific number in a list. The program is shown in Figure 1.

Figure 1

1  values = [12, 45, 68, 23, 99, 54]
2  target = int(input("Enter number: "))
3  found = False
4  i = 0
5  while i < len(values) - 1:
6      if values[i] == target:
7          found = True
8      i = i + 1
9  if found == True:
10     print("Value located")
11 else:
12     print("Value not located")

State the line number from the program in Figure 1 which contains the error that stops the program from sometimes working correctly.

[1]
Markscheme

Searching algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Searching algorithms

33 exam-style questions on AQA GCSE Computer Science Searching algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank