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 ...

Assessment: Computer Science 4CP0 | Paper 2 Mock 01 | Written Paper 2 Subject: Computer Science - 4CP0

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

numbers = [104, 217, 386, 451]words = ["COIN", "MAP", "VASE", "DRUM"]wanted = int(input("Enter number: "))found = Falsefor position in range(0, 4):if numbers[position] == wanted:# missing code© EAGLE BEACON GLOBAL

(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]

Answer Details

(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 = True

print(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:

  • Input 217, expected display MAP [2].
  • Input 999, expected display NOT FOUND [2].

The first checks a stored value and its linked array item; the second checks the unsuccessful-search path.

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning