Question 1 Report
A heritage centre uses a program to show a word describing an artefact when a visitor types its three-digit catalogue number. Fig. 1 shows part of the code in the code editor. The array positions hold the catalogue numbers and the related display words. The program must search the number data entered, then display the correct word. If the input is not stored, it must display NOT FOUND.
Fig. 1
(a) Identify the array index used to obtain the word VASE. [2]
(b) Complete the missing code so that the matching word is displayed and found is changed to True. [3]
(c) Write the code that should be placed after the for loop to display NOT FOUND only when no matching number was found. [3]
(d) Give two test inputs, with the expected display for each, that would test this program. One test must use a number in the array and one must use a number not in the array. [4]
(a) The index for VASE is 2 [1]. Python arrays use zero-based indexing [1], so the third item has index 2.
(b) Inside the existing if block, the missing code is:
print(words[position])
found = Trueprint(words[position]) displays the word at the same position as the matching catalogue number [1], and found = True records that a match exists [1]. Both statements must be indented inside the if block [1].
(c) After, not inside, the for loop, write:
if not found:
print("NOT FOUND")The Boolean test is correct [1], the required message is printed [1], and placing it after the loop prevents NOT FOUND being displayed before every non-matching item [1].
(d) Suitable tests are:
217, expected display MAP [2].999, expected display NOT FOUND [2].The first checks a stored value and its linked array item; the second checks the unsuccessful-search path.
Everything you need to excel in your exams