Oxford Cambridge and RSA
GCSE (9-1) Computer Science
Algorithms & Programming
J277/02
Topic: String Manipulation & ASCII
Time allowed: 45 minutes
Centre number Candidate number
First name Last name
INSTRUCTIONS INFORMATION
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'))
(c) print(CHR(50))
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]
Explanation:
Corrected Code:
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
7
State the output of the following string operations on the variable module = "Computer Science".
[3]
print(module.substring(0, 4))
print(module.right(3))
print(module.length)
8
A user must enter a password. The password must be at least 8 characters long.
Write a simple algorithm that:
  • Asks for the password.
  • Uses a WHILE loop to keep asking until the password length is 8 or more.
[4]
9
Given word1 = "Apple" and word2 = "Zebra".
State whether the following boolean expressions evaluate to True or False.
[3]
word1.length == 5
word1 < word2 (Hint: Alphabetical comparison)
word1.substring(0, 1) == "a"
END OF QUESTION PAPER