Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 19

Extend the program in Figure 1. Your answer must be written in Python.

The program should get the user to enter a colour and perform a linear search on the list colours to find if the colour is in the list or not.

The program should:

  • ask the user which colour they would like to find
  • output the message True if the colour is found
  • output the message False if the colour is not found.

You must write your own linear search routine using a loop and not use built-in search functions or the direct in membership operator (e.g., if search_term in colours: is not allowed).

You should use meaningful variable name(s) and Python syntax in your answer.

Figure 1

colours = ["red", "blue", "green", "yellow", "purple", "orange"]
[7]
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