Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 10

A student has written a program in Python to search for a specific name in a list.

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

Figure 1

1  names = ["Alice", "Bob", "Charlie", "Diana"]
2  target = input("Enter name to find: ")
3  found = False
4  current = 0
5  while current < len(names) - 1:
6      if names[current] == target:
7          found = True
8      current = current + 1
9  if found == True:
10     print("Name is in list")
11 else:
12     print("Name is not in list")
[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