In this guide:
Python vs. Pseudocode String Methods
Python treats strings as arrays and uses dot-notation (like .upper()). In standard Cambridge pseudocode, you must use explicit built-in functions.
| Concept | 🐍 Python (Wrong for Exams) | 📘 Cambridge Pseudocode (Correct) |
|---|---|---|
| Length of a String | len(Word) | LENGTH(Word) |
| Uppercase | Word.upper() | UCASE(Word) |
| Extraction | Word[0:3] | SUBSTRING(Word, 1, 3) |
| Concatenation | "Hello " + Name | "Hello " & Name |
1. String Concatenation
Concatenation is the process of joining two strings together. In Cambridge pseudocode, this is done using the ampersand (&) symbol, not the plus (+) sign.
DECLARE FirstName : STRING
DECLARE LastName : STRING
DECLARE FullName : STRING
FirstName ← "Alan"
LastName ← "Turing"
// Notice the space added in the middle!
FullName ← FirstName & " " & LastName
2. Substrings and Length
Examiners love asking you to extract data from a string (like pulling the first 3 letters of a surname to generate a username). You use the SUBSTRING(String, StartPos, Length) function for this. Remember, strings are 1-indexed in pseudocode!
DECLARE Word : STRING
DECLARE Code : STRING
Word ← "Computer"
// Extracts 3 characters starting from position 1 ("Com")
Code ← SUBSTRING(Word, 1, 3)
// Gets the length of the string (8)
OUTPUT LENGTH(Word)
3. Math Routines (ROUND & RANDOM)
You don't need to write complex algorithms for basic math. The syllabus provides built-in functions for rounding numbers and generating random values.
REAL number to a specific number of decimal places. e.g., ROUND(3.14159, 2) returns 3.14.
INT(RANDOM() * 10) + 1.
Interactive Exam Practice
Scenario: Write an algorithm that takes a user's password as input. If the password is less than 8 characters long, output "Too short". Otherwise, output the password in all uppercase letters.
Hover or tap the black box to reveal the examiner's solution. Click Run Code to test it instantly!
DECLARE Password : STRING OUTPUT "Enter a password:" INPUT Password IF LENGTH(Password) < 8 THEN OUTPUT "Too short" ELSE OUTPUT UCASE(Password) ENDIF