Time allowed: 45 minutes
| Centre number |
| | | |
|
Candidate number |
| | | |
| First name |
|
Last name |
INSTRUCTIONS
- Use black ink.
- Answer all the questions.
INFORMATION
- The total mark for this paper is 30.
- The marks for each question are shown in brackets [ ].
Turn over
Section A: Low-Frequency "Ghost Topics"
1
The functions
ASC() and
CHR() are used to convert characters to their numeric ASCII values and vice versa.
ASC('A') returns 65.
ASC('a') returns 97.
ASC('0') returns 48.
Determine the output of the following algorithms:
[3]
(a) print(CHR(ASC('A') + 3))
(b) print(ASC('c') - ASC('a'))
2
A student writes a program to ask for a command. The command "START" should trigger a game.
The code fails if the user types "Start" or "start".
01 command = input("Enter command: ")
02 if command == "START":
03 print("Game Starting...")
04 else:
05 print("Unknown command")
(a) Explain why the input "start" results in "Unknown command".
[1]
(b) Rewrite Line 02 using a string manipulation method (
.upper or
.lower) so that "start", "Start", and "START" are all accepted.
[1]
3
Trace the execution of this algorithm, which manipulates a string variable.
Note: In OCR ERL, substring(x, y) takes x as the starting index (0-based) and y as the number of characters.
text = "ROBOT"
newText = ""
count = 0
WHILE count < 3
letter = text.substring(count, 1)
newText = newText + letter + "-"
count = count + 1
ENDWHILE
print(newText)
[4]
| count |
letter |
newText |
Condition (count < 3) |
Output |
| 0 |
|
|
True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Turn over
4
Write a function called
getInitials that takes a full name (e.g., "Alan Turing") as a parameter.
The function must:
- Extract the first character of the string.
- Find the position of the space " ".
- Extract the character immediately after the space.
- Return the two initials in Uppercase.
Example: Input "alan turing" should return "AT".
[6]
5
A student attempts to convert a name to uppercase with this code:
name = "ben"
name.upper()
print(name)
The output is still "ben".
Explain why the output is not "BEN" and write the corrected line of code.
[2]
Section B: High-Frequency Baseline Skills
6
A program creates a username by taking the first 3 letters of a surname and adding the length of the surname.
Fill in the missing keywords/methods.
[3]
surname = input("Enter surname: ")
part1 = surname.........................(3) # Get first 3 letters
part2 = surname......................... # Get the number of characters
username = part1 + .....................(part2) # Join them (requires casting)
print(username)
Turn over