Char Points 0 / 30
Char Rank Char Scraper

Topic 2.2.6: String Manipulation

Substrings, Casting & ASCII Logic.

1 [3 Marks]
ASC('A')=65. ASC('a')=97.
Calculate:
  • CHR(ASC('A') + 3)
  • ASC('c') - ASC('a')
  • CHR(50) (Note: '0' is 48)
✅ Mark Scheme
  • D (68)
  • 2 (99 - 97)
  • '2' (Character 2, not integer 2)
Score:
2 [2 Marks]
01 command = input("Enter command: ") 02 if command == "START": 03 print("Game Starting...") 04 else: 05 print("Unknown command")
(a) Why does "Start" fail?
(b) Rewrite IF statement to accept any case (using upper/lower).
✅ Mark Scheme

(a) Case-sensitive comparison. "Start" != "START".

(b) if command.upper() == "START":

Score:
3 [4 Marks]
text = "ROBOT" newText = "" count = 0 WHILE count < 3 letter = text.substring(count, 1) newText = newText + letter + "-" count = count + 1 ENDWHILE print(newText)
Trace output.

Trace Table:

countletternewTextOutput
✅ Mark Scheme

Output: R-O-B-

(Loops 0, 1, 2. Extracts R, O, B. Appends hyphen each time).

Score:
4 [6 Marks]
Write a function getInitials(name) that returns uppercase initials.
e.g. "alan turing" -> "AT".
✅ Mark Scheme
function getInitials(name)
  first = name.substring(0, 1)
  spacePos = name.index(" ")
  second = name.substring(spacePos + 1, 1)
  combined = first + second
  return combined.upper()
endfunction
Score:
5 [2 Marks]
name = "ben" name.upper() print(name)
Output is "ben". Why? Fix logic.
✅ Mark Scheme

Reason: String methods return a new string, they don't change the original.

Fix: name = name.upper()

Score:
6 [3 Marks]
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)
Fill blanks (First 3 letters + Length).
✅ Mark Scheme
  • 1. left (or substring)
  • 2. length
  • 3. str (Must cast int length to string)
Score:
7 [3 Marks]
module = "Computer Science"
Output of:
  • module.substring(0, 4)
  • module.right(3)
  • module.length
✅ Mark Scheme
  • Comp
  • nce
  • 16
Score:
8 [4 Marks]
Write a WHILE loop that asks for password until length >= 8.
✅ Mark Scheme
pw = input("Password: ")
while len(pw) < 8:
    print("Too short")
    pw = input("Password: ")
Score:
9 [3 Marks]
word1 = "Apple", word2 = "Zebra"
True or False:
  • word1.length == 5
  • word1 < word2
  • word1.substring(0, 1) == "a"
✅ Mark Scheme
  • True
  • True (Apple < Zebra alphabetically)
  • False ("A" != "a")
Score: