Skip to content

Course home

Searching algorithms

Searching algorithms

EasyMediumHard
12345678910111213141516171819202122
Question 12

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

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

The program should:

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

You must write your own linear search routine and not use any built-in search function/operator (such as in, index(), or count()) on the list to perform the search.

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

Figure 12

capitals = ["Paris", "Berlin", "Rome", "Madrid",
            "Lisbon", "Vienna"]
[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