Easy1 markMultiple Choice
ProgrammingGeneralstring manipulationindexing

AQA GCSE · Question 01.5 · Programming

The subroutine POSITION finds the first position of a character in a string.
For example, POSITION('Computing', 'p') would return 3.

The variable z is assigned a value using the statement:
z ← POSITION(landmark, 't')

Using Figure 1, what value is assigned to z?
(Note: The paper states to assume 0-based indexing unless specified otherwise.)

Answer options:

A.

-1

B.

3

C.

4

D.

5

How to approach this question

1. Identify the value of `landmark`: "Alcatraz Island". 2. The function is `POSITION(landmark, 't')`, which looks for the first occurrence of the character 't'. 3. The general instruction for this paper is to assume 0-based indexing. 4. Let's find the index of 't' in "Alcatraz Island": - A is at index 0 - l is at index 1 - c is at index 2 - a is at index 3 - t is at index 4 5. The first position of 't' is 4.

Full Answer

C.4✓ Correct
The correct answer is C (4). The `POSITION` function finds the index of the first occurrence of a character. The string `landmark` is "Alcatraz Island". Using 0-based indexing, the first 't' is at index 4.
The `POSITION` function (often called `find` or `indexOf` in programming languages) searches for a character or substring within a string and returns the index of its first occurrence. The exam specifies using 0-based indexing, meaning the first character is at index 0, the second at index 1, and so on. In the string "Alcatraz Island": - Index 0: 'A' - Index 1: 'l' - Index 2: 'c' - Index 3: 'a' - Index 4: 't' The first time the character 't' appears is at index 4.

Common mistakes

✗ Using 1-based indexing instead of 0-based indexing, which would lead to the answer 5.\n✗ Confusing the character to find with its position.

Practice the full AQA GCSE Computer Science Paper 1 Python

31 questions · hints · full answers · grading

More questions from this exam