Paper 2: Pseudocode step by step
Paper 2 pseudocode: the complete guide
On this page
- Paper 2 at a glance
- The rules of writing pseudocode
- Input, output and operators
- Selection: IF and CASE
- Iteration: FOR, WHILE and REPEAT
- Totalling, counting, maximum, minimum, average
- String handling
- Validation, verification and test data
- Procedures, functions and parameters
- Arrays, linear search and bubble sort
- File handling
- Trace tables and finding errors
- The 15-mark scenario question
- One-page reference card
Every pseudocode topic on Cambridge O Level Computer Science (2210) Paper 2, in the exact style the exam prints. Each topic has a worked example and questions like the real paper. Try each one in the space, then press Check my answer and tick it off.
Paper 2 at a glance
0478 / 2210 syllabus for 2026–2028 · Topics 7 to 10
Big ideaPaper 2 rewards clear, exact steps. You already think in steps; this paper teaches you to write them down.
Paper 2 Algorithms, Programming and Logic is 1 hour 45 minutes, 75 marks, every question compulsory, no calculator. Topics 7 (algorithm design) and 8 (programming) are where pseudocode lives; topics 9 (databases and SQL) and 10 (Boolean logic) are the rest of the paper and are not covered here.
| Part of the paper | What students do | Typical marks |
|---|---|---|
| Short questions | data types, validation checks, test data, loop types, library routines | 1 to 4 each |
| Complete / correct an algorithm | fill in gaps, find and fix errors by line number | 4 to 6 |
| Trace tables | dry-run an algorithm or flowchart with given data | 4 to 6 |
| Write an algorithm | short pseudocode for a stated task | 4 to 8 |
| Scenario question (always last) | a full program for an unseen context, about 30 minutes | 15 (AO2 9 + AO3 6) |
The rules of writing pseudocode
Syllabus 8.1.1 · 8.1.2 · pseudocode guide in section 4
Big ideaPseudocode is just English with a few fixed words. Learn the ten rules once and every question reads easier.
Cambridge prints every algorithm in one fixed style. Students who write in the same style read questions faster and lose fewer marks to ambiguity.
| Rule | Example |
|---|---|
| Keywords in CAPITALS | IF FOR REPEAT OUTPUT |
| Identifiers in PascalCase: start with a capital letter, only letters and digits, no spaces or _ | NumberOfPlayers TotalToPay |
| Assignment uses the arrow ← (never =) | Counter ← Counter + 1 |
| Declare a variable with its data type | DECLARE Counter : INTEGER |
| A constant holds a literal value only | CONSTANT HourlyRate ← 6.50 |
| Comments start with // | // works out the total |
| Indent the inside of a structure by 4 spaces; THEN, ELSE and CASE lines by 2 | see every example below |
The five data types
| Type | Holds | Literal looks like | Use it for |
|---|---|---|---|
| INTEGER | whole numbers | 5 -3 | counts, ages, number of items |
| REAL | numbers with a fractional part | 4.7 0.0 -4.0 | prices, heights, averages |
| CHAR | exactly one character | 'x' '@' | a grade letter, a menu choice |
| STRING | zero or more characters | "Hello" "" | names, codes, phone numbers |
| BOOLEAN | TRUE or FALSE | TRUE FALSE | flags: Found, Swap, Valid |
// Works out the cost of a cinema trip CONSTANT TicketPrice ← 8.50 DECLARE Tickets : INTEGER DECLARE Cost : REAL OUTPUT "How many tickets?" INPUT Tickets Cost ← Tickets * TicketPrice OUTPUT "Total cost: $", Cost
How many tickets? 3 Total cost: $25.5
Your turn
Give the most suitable data type for each item.
| Item | Data type |
|---|---|
| (a) the number of passengers on a bus | |
| (b) a person's height in metres | |
| (c) whether a door is open | |
| (d) the first letter of a surname | |
| (e) a telephone number such as 03001234567 |
Check my answermodel answer and marking points
| Item | Answer | Why |
|---|---|---|
| (a) | INTEGER | whole number |
| (b) | REAL | has a decimal part, e.g. 1.62 |
| (c) | BOOLEAN | only two states |
| (d) | CHAR | one character |
| (e) | STRING | leading 0 must be kept; no arithmetic is done with it |
1 mark each. Common wrong answer: INTEGER for (e).
This pseudocode contains four errors. Identify each error and write the corrected statement.
01DECLARE 1stScore : INTEGER02DECLARE Average Mark : REAL03CONSTANT PassMark ← Score + 1004Total = Total + 1
Check my answermodel answer and marking points
| Line | Error | Correction |
|---|---|---|
| 01 | identifier starts with a digit | DECLARE FirstScore : INTEGER |
| 02 | identifier contains a space | DECLARE AverageMark : REAL |
| 03 | a constant must be a literal value | CONSTANT PassMark ← 50 |
| 04 | assignment uses ← not = | Total ← Total + 1 |
A shop adds a sales tax of 20% to every price. Explain two reasons for storing the tax rate as a constant, and write the statement that declares it.
Check my answermodel answer and marking points
- Readable:
Price * TaxRateexplains itself, 0.2 does not. - If the rate changes, it is changed in one place only.
- The value cannot be changed by mistake while the program runs.
CONSTANT TaxRate ← 0.2
Any two reasons + the declaration.
Input, output and operators
Syllabus 8.1.3 · 8.1.4(f) · 8.1.7
Big ideaComputers only do maths and comparisons. DIV and MOD are the two that surprise people, and they are easy.
Every INPUT in an exam answer should come after an OUTPUT that tells the user what to type. OUTPUT can show several values separated by commas.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + – * / | add, subtract, multiply, divide | 17 / 4 | 4.25 |
| ^ | raised to the power of | 2 ^ 3 | 8 |
| DIV(a, b) | whole-number division (remainder thrown away) | DIV(17, 4) | 4 |
| MOD(a, b) | the remainder | MOD(17, 4) | 1 |
| = < <= > >= <> | compare; the result is BOOLEAN | 5 <> 4 | TRUE |
| AND OR NOT | combine conditions | (7 > 3) AND (2 > 5) | FALSE |
| ROUND(x, places) | round to a number of decimal places | ROUND(3.14159, 2) | 3.14 |
| RANDOM() | a random number from 0 to 1 | ROUND(RANDOM() * 5, 0) + 1 | a whole number 1 to 6 |
OUTPUT "Enter the number of minutes" INPUT TotalMinutes Hours ← DIV(TotalMinutes, 60) Minutes ← MOD(TotalMinutes, 60) OUTPUT TotalMinutes, " minutes is ", Hours, " hours and ", Minutes, " minutes"
Your turn
State the value of each expression.
| Expression | Value |
|---|---|
DIV(23, 4) | |
MOD(23, 4) | |
2 ^ 3 + 1 | |
17 / 4 | |
(7 > 3) AND (2 > 5) | |
NOT (4 <> 4) |
Check my answermodel answer and marking points
| Expression | Value |
|---|---|
DIV(23, 4) | 5 |
MOD(23, 4) | 3 |
2 ^ 3 + 1 | 9 |
17 / 4 | 4.25 |
(7 > 3) AND (2 > 5) | FALSE |
NOT (4 <> 4) | TRUE |
OUTPUT DIV(23, 4), " ", MOD(23, 4), " ", 2 ^ 3 + 1, " ", 17 / 4, " ", (7 > 3) AND (2 > 5), " ", NOT (4 <> 4)
Write pseudocode to input a number of seconds and output it as minutes and seconds. For example, 200 is output as 3 minutes 20 seconds.
Check my answermodel answer and marking points
OUTPUT "Enter a number of seconds" INPUT Seconds Minutes ← DIV(Seconds, 60) Remainder ← MOD(Seconds, 60) OUTPUT Minutes, " minutes ", Remainder, " seconds"
- 1 prompt + INPUT
- 1 DIV by 60
- 1 MOD by 60
- 1 OUTPUT with both values and labels
Write a condition for each of these. (a) Age is from 13 to 19 inclusive. (b) Letter is a vowel (lower case only). (c) Score is not zero.
Check my answermodel answer and marking points
// (a) Age >= 13 AND Age <= 19 // (b) Letter = 'a' OR Letter = 'e' OR Letter = 'i' OR Letter = 'o' OR Letter = 'u' // (c) Score <> 0
(b) Each comparison must name the variable again: Letter = 'a' OR 'e' is wrong.
Selection: IF and CASE
Syllabus 8.1.4(b) · 8.1.5
Big ideaIF is how a program makes a choice. Ask the biggest question first and work down.
IF tests any condition. CASE picks one branch from a list of single values. Use IF for ranges (marks, prices, ages) and CASE for menus and codes.
OUTPUT "Enter the mark (0 to 100)" INPUT Mark IF Mark >= 80 THEN Grade ← 'A' ELSE IF Mark >= 60 THEN Grade ← 'B' ELSE IF Mark >= 40 THEN Grade ← 'C' ELSE Grade ← 'U' ENDIF ENDIF ENDIF OUTPUT "Grade: ", Grade
OUTPUT "Enter two numbers" INPUT A INPUT B OUTPUT "Choose 1 Add, 2 Subtract, 3 Multiply" INPUT Choice CASE OF Choice 1 : OUTPUT A + B 2 : OUTPUT A - B 3 : OUTPUT A * B OTHERWISE OUTPUT "Invalid choice" ENDCASE
Your turn
A car park charges nothing for up to 2 hours, $3 for more than 2 hours up to 5 hours, and $8 for more than 5 hours. Write pseudocode to input the hours parked and output the charge.
Check my answermodel answer and marking points
OUTPUT "How many hours were you parked?" INPUT Hours IF Hours <= 2 THEN Charge ← 0 ELSE IF Hours <= 5 THEN Charge ← 3 ELSE Charge ← 8 ENDIF ENDIF OUTPUT "Charge: $", Charge
- prompt and INPUT
- first test (≤ 2) → 0
- second test (≤ 5) → 3
- otherwise → 8
- OUTPUT with label
Write a CASE statement that inputs a day number 1 to 7 and outputs the day's name (1 = Monday). Any other number outputs Invalid day number.
Check my answermodel answer and marking points
INPUT DayNumber CASE OF DayNumber 1 : OUTPUT "Monday" 2 : OUTPUT "Tuesday" 3 : OUTPUT "Wednesday" 4 : OUTPUT "Thursday" 5 : OUTPUT "Friday" 6 : OUTPUT "Saturday" 7 : OUTPUT "Sunday" OTHERWISE OUTPUT "Invalid day number" ENDCASE
- CASE OF DayNumber … ENDCASE
- seven correct branches
- OTHERWISE with the message
- INPUT before CASE
This algorithm should output Distinction for 75 or more, Pass for 40 to 74 and Fail below 40. Explain why it does not work, and correct it.
01IF Mark >= 4002 THEN03 Result ← "Pass"04 ELSE05 IF Mark >= 7506 THEN07 Result ← "Distinction"08 ELSE09 Result ← "Fail"10 ENDIF11ENDIF
Check my answermodel answer and marking points
A mark of 80 passes the first test (80 ≥ 40), so it gets Pass; the Distinction branch can never be reached, because it only runs when Mark is below 40. Test 75 first:
IF Mark >= 75 THEN Result ← "Distinction" ELSE IF Mark >= 40 THEN Result ← "Pass" ELSE Result ← "Fail" ENDIF ENDIF OUTPUT Result
Iteration: FOR, WHILE and REPEAT
Syllabus 8.1.4(c)
Big ideaA loop saves you writing the same line 30 times. The only question is: how does it know when to stop?
| Loop | Type | Condition tested | Runs | Choose it when |
|---|---|---|---|---|
| FOR … NEXT | count-controlled | — | a fixed number of times | you know how many times (30 students) |
| WHILE … DO … ENDWHILE | pre-condition | before the body | 0 or more times | it may not need to run at all (a rogue value could come first) |
| REPEAT … UNTIL | post-condition | after the body | at least once | the body must happen once (ask for input, then check it) |
FOR Count ← 10 TO 0 STEP -2 OUTPUT Count NEXT Count
Total ← 0 OUTPUT "Enter a number (-1 to stop)" INPUT Number WHILE Number <> -1 DO Total ← Total + Number OUTPUT "Enter a number (-1 to stop)" INPUT Number ENDWHILE OUTPUT "Total is ", Total
REPEAT OUTPUT "Enter your age (11 to 18)" INPUT Age UNTIL Age >= 11 AND Age <= 18
Your turn
Write a FOR loop that outputs the 5 times table from 5 x 1 = 5 to 5 x 12 = 60.
Check my answermodel answer and marking points
FOR Count ← 1 TO 12 OUTPUT "5 x ", Count, " = ", 5 * Count NEXT Count
- FOR 1 TO 12 … NEXT
- 5 * Count
- OUTPUT with the text in the right order
Rewrite this algorithm using (a) a REPEAT … UNTIL loop and (b) a WHILE loop.
FOR Count ← 1 TO 5 OUTPUT Count * Count NEXT Count
Check my answermodel answer and marking points
(a)
Count ← 1 REPEAT OUTPUT Count * Count Count ← Count + 1 UNTIL Count > 5
(b)
Count ← 1 WHILE Count <= 5 DO OUTPUT Count * Count Count ← Count + 1 ENDWHILE
Marks: start value set before the loop, Count increased inside the loop, correct stop condition for each.
Name the most suitable loop for each task and give a reason. (a) Input the marks of 30 students. (b) Keep asking for a password until it is correct. (c) Add up prices until the user enters 0 (the first value could be 0).
Check my answermodel answer and marking points
- (a) FOR: the number of repetitions (30) is known.
- (b) REPEAT … UNTIL: the password must be asked for at least once.
- (c) WHILE: the condition is checked first, so the loop may run zero times.
Write a number-guessing game. The program picks a random whole number from 1 to 100. The user keeps guessing; after each wrong guess output Too high or Too low. When the guess is correct output how many guesses were taken.
Check my answermodel answer and marking points
Secret ← ROUND(RANDOM() * 99, 0) + 1 Attempts ← 0 REPEAT OUTPUT "Guess the number (1 to 100)" INPUT Guess Attempts ← Attempts + 1 IF Guess > Secret THEN OUTPUT "Too high" ENDIF IF Guess < Secret THEN OUTPUT "Too low" ENDIF UNTIL Guess = Secret OUTPUT "Correct! You took ", Attempts, " guesses"
- random number 1 to 100
- count set to 0, increased each guess
- loop until correct
- Too high / Too low with selection
- final OUTPUT with the count
- prompt before each INPUT
Totalling, counting, maximum, minimum, average
Syllabus 7.4 · 8.1.4(d)
Big ideaFour tiny patterns (total, count, highest, lowest) are in almost every paper. Learn their shape and they are free marks.
Four patterns appear in almost every Paper 2. Teach them as fixed shapes students can write without thinking.
| Method | Before the loop | Inside the loop |
|---|---|---|
| Totalling | Total ← 0 | Total ← Total + Value |
| Counting | Count ← 0 | IF condition THEN Count ← Count + 1 |
| Maximum | Highest ← a very low value (or the first value) | IF Value > Highest THEN Highest ← Value |
| Minimum | Lowest ← a very high value (or the first value) | IF Value < Lowest THEN Lowest ← Value |
| Average | — | after the loop: Average ← Total / NumberOfValues |
// one week of temperatures: total, hot days, highest, lowest, average Total ← 0 HotDays ← 0 Highest ← -100 Lowest ← 100 FOR Day ← 1 TO 7 OUTPUT "Enter the temperature for day ", Day INPUT Temperature Total ← Total + Temperature IF Temperature > 25 THEN HotDays ← HotDays + 1 ENDIF IF Temperature > Highest THEN Highest ← Temperature ENDIF IF Temperature < Lowest THEN Lowest ← Temperature ENDIF NEXT Day Average ← ROUND(Total / 7, 1) OUTPUT "Average: ", Average, " Highest: ", Highest, " Lowest: ", Lowest OUTPUT "Days above 25: ", HotDays
… (7 prompts) … Average: 24.1 Highest: 31 Lowest: 18 Days above 25: 3
Your turn
Write pseudocode to input the prices of 10 items. Output the total cost, the average price rounded to 2 decimal places, and how many items cost more than $50.
Check my answermodel answer and marking points
Total ← 0 Expensive ← 0 FOR Item ← 1 TO 10 OUTPUT "Enter the price of item ", Item INPUT Price Total ← Total + Price IF Price > 50 THEN Expensive ← Expensive + 1 ENDIF NEXT Item OUTPUT "Total: $", Total OUTPUT "Average price: $", ROUND(Total / 10, 2) OUTPUT "Items over $50: ", Expensive
- Total and count set to 0 before the loop
- loop 10 times with prompt and INPUT
- Total ← Total + Price
- IF Price > 50 then count + 1
- average with ROUND(…, 2) after the loop
- three outputs with labels
The numbers input are all between 1 and 999. Complete the algorithm so that it outputs the largest and smallest of 50 numbers.
Largest ← Smallest ← 1000 FOR Count ← 1 TO INPUT Number IF Number > Largest THEN ← Number ENDIF IF THEN Smallest ← Number ENDIF NEXT OUTPUT "Largest: ", Largest, " Smallest: ", Smallest
Check my answermodel answer and marking points
0(any value below 1)50LargestNumber < SmallestCount
Largest ← 0 Smallest ← 1000 FOR Count ← 1 TO 50 INPUT Number IF Number > Largest THEN Largest ← Number ENDIF IF Number < Smallest THEN Smallest ← Number ENDIF NEXT Count OUTPUT "Largest: ", Largest, " Smallest: ", Smallest
A rain gauge records rainfall in millimetres for 30 days. Write pseudocode to input the 30 readings and output the total rainfall, the number of dry days (0 mm) and the day number with the most rain.
Check my answermodel answer and marking points
Total ← 0 DryDays ← 0 Wettest ← -1 WettestDay ← 0 FOR Day ← 1 TO 30 OUTPUT "Enter the rainfall in mm for day ", Day INPUT Rain Total ← Total + Rain IF Rain = 0 THEN DryDays ← DryDays + 1 ENDIF IF Rain > Wettest THEN Wettest ← Rain WettestDay ← Day ENDIF NEXT Day OUTPUT "Total rainfall: ", Total, " mm" OUTPUT "Dry days: ", DryDays OUTPUT "Wettest day: day ", WettestDay, " with ", Wettest, " mm"
Key idea: store the day number at the same moment as the new maximum (WettestDay ← Day).
String handling
Syllabus 8.1.4(e)
Big ideaA string is a row of boxes, one letter in each. SUBSTRING just picks some boxes out.
| Function | Returns | Example | Result |
|---|---|---|---|
| LENGTH(s) | number of characters | LENGTH("Happy Days") | 10 |
| SUBSTRING(s, start, length) | part of the string; position 1 is the first character | SUBSTRING("Happy Days", 1, 5) | "Happy" |
| UCASE(s) | upper case copy | UCASE("Happy") | "HAPPY" |
| LCASE(s) | lower case copy | LCASE('W') | 'w' |
OUTPUT "Enter a sentence" INPUT Sentence Vowels ← 0 FOR Position ← 1 TO LENGTH(Sentence) Letter ← LCASE(SUBSTRING(Sentence, Position, 1)) IF Letter = "a" OR Letter = "e" OR Letter = "i" OR Letter = "o" OR Letter = "u" THEN Vowels ← Vowels + 1 ENDIF NEXT Position OUTPUT "Number of vowels: ", Vowels
Your turn
State what each function call returns.
| Call | Returns |
|---|---|
LENGTH("Computer Science") | |
SUBSTRING("Computer Science", 10, 3) | |
UCASE("igcse") | |
LCASE(SUBSTRING("PAKISTAN", 1, 3)) |
Check my answermodel answer and marking points
| Call | Returns |
|---|---|
LENGTH("Computer Science") | 16 (the space counts) |
SUBSTRING("Computer Science", 10, 3) | "Sci" |
UCASE("igcse") | "IGCSE" |
LCASE(SUBSTRING("PAKISTAN", 1, 3)) | "pak" |
OUTPUT LENGTH("Computer Science"), SUBSTRING("Computer Science", 10, 3), UCASE("igcse"), LCASE(SUBSTRING("PAKISTAN", 1, 3))
A password is strong if it has at least 8 characters and contains at least one digit. Write pseudocode to input a password and output Strong password or Weak password.
Check my answermodel answer and marking points
OUTPUT "Enter a password" INPUT Password HasDigit ← FALSE FOR Position ← 1 TO LENGTH(Password) Character ← SUBSTRING(Password, Position, 1) IF Character >= "0" AND Character <= "9" THEN HasDigit ← TRUE ENDIF NEXT Position IF LENGTH(Password) >= 8 AND HasDigit = TRUE THEN OUTPUT "Strong password" ELSE OUTPUT "Weak password" ENDIF
Also tested: abc123 gives Weak password (too short).
- prompt + INPUT
- Boolean flag set to FALSE before the loop
- loop through every character with SUBSTRING
- digit test
- length test with LENGTH
- both conditions joined with AND, two outputs
Write pseudocode to input a word and output its letters in reverse order, one letter per line.
Check my answermodel answer and marking points
OUTPUT "Enter a word" INPUT Word FOR Position ← LENGTH(Word) TO 1 STEP -1 OUTPUT SUBSTRING(Word, Position, 1) NEXT Position
- loop starts at LENGTH(Word)
- STEP -1 down to 1
- SUBSTRING(Word, Position, 1)
Validation, verification and test data
Syllabus 7.5 · 7.6
Big ideaNever trust what a user types. A validation loop keeps asking until the answer makes sense.
Validation is the computer checking that data is reasonable and follows the rules. Verification checks that data was copied or typed correctly. Valid data can still be wrong: 17 is a valid age, even if the student is 15.
| Check | What it tests | Pseudocode idea |
|---|---|---|
| Range | between a lower and an upper limit | Mark < 0 OR Mark > 100 |
| Length | number of characters | LENGTH(Password) < 8 |
| Type | the right kind of data, e.g. a whole number | Number <> ROUND(Number, 0) |
| Presence | something has been entered | Name = "" |
| Format | a set pattern, e.g. two letters then four digits | SUBSTRING each position and test it |
| Check digit | an extra digit calculated from the others (ISBN, barcodes) catches typing errors | explained, not usually coded |
OUTPUT "Enter a mark between 0 and 100" INPUT Mark WHILE Mark < 0 OR Mark > 100 DO OUTPUT "Invalid. The mark must be between 0 and 100. Try again" INPUT Mark ENDWHILE
| Verification | How |
|---|---|
| Double entry | the data is typed twice and the two copies are compared; a mismatch means re-enter |
| Visual check | the user reads the data on screen and confirms it matches the original |
Test data
For an input that must be a whole number from 1 to 50:
| Type | Meaning | Example values |
|---|---|---|
| Normal | ordinary data that should be accepted | 25, 7 |
| Abnormal | data that should be rejected | -5, 75, "ten" |
| Extreme | the largest and smallest accepted values | 1 and 50 |
| Boundary | each limit and the value just outside it | 0 and 1, 50 and 51 |
Your turn
Name the validation check that would be used for each of these.
| Rule | Check |
|---|---|
| (a) a surname must be entered | |
| (b) a month number must be 1 to 12 | |
| (c) a username must be 6 to 12 characters | |
| (d) a product code must be like AB1234 |
Check my answermodel answer and marking points
| Rule | Check |
|---|---|
| (a) | presence check |
| (b) | range check |
| (c) | length check |
| (d) | format check |
An age must be a whole number from 11 to 18. Give one example of each type of test data and the reason for using it: normal, abnormal, extreme, boundary.
Check my answermodel answer and marking points
| Type | Example | Reason |
|---|---|---|
| Normal | 14 | should be accepted |
| Abnormal | 25 (or -3, or "twelve") | should be rejected |
| Extreme | 18 (or 11) | largest / smallest value that is accepted |
| Boundary | 18 and 19 (or 10 and 11) | accepted limit and the rejected value next to it |
Write pseudocode to set a new password. It must be at least 8 characters long (length check), then be verified by double entry. Keep asking until the two entries match, then output Password saved.
Check my answermodel answer and marking points
REPEAT OUTPUT "Enter a new password (at least 8 characters)" INPUT Password WHILE LENGTH(Password) < 8 DO OUTPUT "Too short. Enter at least 8 characters" INPUT Password ENDWHILE OUTPUT "Enter the password again" INPUT Check IF Check <> Password THEN OUTPUT "The passwords do not match. Start again" ENDIF UNTIL Check = Password OUTPUT "Password saved"
- prompts + inputs
- length check with LENGTH and a loop
- second entry input
- comparison of the two entries
- outer loop repeats until they match
- final message
A product code must be 6 characters: two upper case letters followed by four digits (e.g. AB1234). Write pseudocode to input a code and output Valid or Invalid.
Check my answermodel answer and marking points
OUTPUT "Enter the product code" INPUT ProductCode Valid ← TRUE IF LENGTH(ProductCode) <> 6 THEN Valid ← FALSE ELSE FOR Position ← 1 TO 6 Character ← SUBSTRING(ProductCode, Position, 1) IF Position <= 2 THEN IF Character < "A" OR Character > "Z" THEN Valid ← FALSE ENDIF ELSE IF Character < "0" OR Character > "9" THEN Valid ← FALSE ENDIF ENDIF NEXT Position ENDIF IF Valid = TRUE THEN OUTPUT "Valid" ELSE OUTPUT "Invalid" ENDIF
Also tested: A12345 and AB123 give Invalid.
- length check first
- loop through the characters with SUBSTRING
- letters test for positions 1–2
- digits test for positions 3–6
- flag + correct output
Procedures, functions and parameters
Syllabus 8.1.6 · 8.1.7 · 8.1.8
Big ideaGive a job a name, write it once, use it anywhere. That is all a procedure or function is.
| Procedure | Function | |
|---|---|---|
| Returns a value? | no | yes, exactly one, with RETURN |
| Header | PROCEDURE Name(P : TYPE) | FUNCTION Name(P : TYPE) RETURNS TYPE |
| Called with | CALL Name(…) as a statement on its own | inside an expression: X ← Name(…) or OUTPUT Name(…) |
| Ends with | ENDPROCEDURE | ENDFUNCTION |
A parameter is the variable in the header that receives a value when the subroutine is called (up to three in this syllabus). A local variable is declared inside a subroutine and only exists there; a global variable is declared in the main program and can be used anywhere. Library routines are ready-made: MOD, DIV, ROUND, RANDOM, LENGTH, SUBSTRING, UCASE, LCASE.
PROCEDURE ShowResult(StudentName : STRING, Mark : INTEGER) OUTPUT StudentName, " scored ", Mark IF Mark >= 50 THEN OUTPUT "Well done" ENDIF ENDPROCEDURE FUNCTION Percentage(Mark : INTEGER, OutOf : INTEGER) RETURNS REAL RETURN ROUND(Mark / OutOf * 100, 1) ENDFUNCTION CALL ShowResult("Sara", 62) OUTPUT "Percentage: ", Percentage(62, 75)
DECLARE Total : INTEGER // global: usable anywhere PROCEDURE AddBonus(Points : INTEGER) DECLARE Bonus : INTEGER // local: exists only inside AddBonus Bonus ← Points * 2 Total ← Total + Bonus ENDPROCEDURE Total ← 10 CALL AddBonus(5) OUTPUT Total
Your turn
Explain two differences between a procedure and a function, and state what is meant by a parameter.
Check my answermodel answer and marking points
- A function returns a value; a procedure does not.
- A function is called as part of an expression (e.g. on the right of ←); a procedure is called with CALL as its own statement.
- A function header states the data type it RETURNS.
- Parameter: a variable in the subroutine header that receives a value passed in when it is called.
Write a function Largest that takes three integers and returns the largest. Then write a statement that outputs the largest of 4, 11 and 7.
Check my answermodel answer and marking points
FUNCTION Largest(A : INTEGER, B : INTEGER, C : INTEGER) RETURNS INTEGER DECLARE Biggest : INTEGER Biggest ← A IF B > Biggest THEN Biggest ← B ENDIF IF C > Biggest THEN Biggest ← C ENDIF RETURN Biggest ENDFUNCTION OUTPUT Largest(4, 11, 7)
- header with three parameters and RETURNS INTEGER
- comparisons to find the largest
- RETURN the value
- ENDFUNCTION
- call inside OUTPUT (no CALL keyword)
Write a function ToFahrenheit that converts a Celsius temperature using F = C × 9 / 5 + 32. Use it in a loop that outputs the conversions for 0, 20, 40, 60, 80 and 100 °C.
Check my answermodel answer and marking points
FUNCTION ToFahrenheit(Celsius : REAL) RETURNS REAL RETURN Celsius * 9 / 5 + 32 ENDFUNCTION FOR Temperature ← 0 TO 100 STEP 20 OUTPUT Temperature, "C = ", ToFahrenheit(Temperature), "F" NEXT Temperature
- function header with parameter and RETURNS REAL
- correct formula returned
- FOR with STEP 20
- function called inside the loop with the loop variable
In the AddBonus example above, identify one local and one global variable, and give one reason why local variables are good practice.
Check my answermodel answer and marking points
- Local: Bonus (or the parameter Points). Global: Total.
- Reason: a local variable cannot be changed by mistake elsewhere in the program; the same name can be reused in other subroutines; memory is freed when the subroutine ends.
Arrays, linear search and bubble sort
Syllabus 8.2 · 7.4
Big ideaAn array is a numbered list in one variable. A loop plus an array can handle 1000 students as easily as 3.
An array is a fixed number of values of the same type under one name, reached by an index. The first index is usually 1. A 2D array has a row index and a column index.
DECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:30, 1:3] OF INTEGER // 30 students x 3 tests StudentNames[1] ← "Ali" Marks[1, 2] ← 74 // student 1, test 2
// Readings[1:7, 1:3] holds 3 temperature readings for each of 7 days FOR Day ← 1 TO 7 DayTotal ← 0 FOR Reading ← 1 TO 3 DayTotal ← DayTotal + Readings[Day, Reading] NEXT Reading OUTPUT "Day ", Day, " average: ", ROUND(DayTotal / 3, 1) NEXT Day
Linear search
Check each element in turn until the item is found or the end is reached. Using WHILE with a Found flag stops as soon as the item is found.
// Names[1:30] already holds 30 names OUTPUT "Enter the name to find" INPUT SearchName Found ← FALSE Index ← 1 WHILE Found = FALSE AND Index <= 30 DO IF Names[Index] = SearchName THEN Found ← TRUE ELSE Index ← Index + 1 ENDIF ENDWHILE IF Found = TRUE THEN OUTPUT SearchName, " found at position ", Index ELSE OUTPUT SearchName, " not found" ENDIF
Bubble sort
Compare each pair of neighbours and swap them if they are in the wrong order. After each pass the largest value has “bubbled” to the end, so the next pass can stop one place earlier. Stop when a whole pass makes no swaps.
// Scores[1:10] already holds 10 scores: sort into ascending order Last ← 10 REPEAT Swap ← FALSE FOR Index ← 1 TO Last - 1 IF Scores[Index] > Scores[Index + 1] THEN Temp ← Scores[Index] Scores[Index] ← Scores[Index + 1] Scores[Index + 1] ← Temp Swap ← TRUE ENDIF NEXT Index Last ← Last - 1 UNTIL NOT Swap OR Last = 1
Your turn
(a) Declare an array to hold 25 names. (b) Declare a 2D array of integers with 6 rows and 4 columns called Points. (c) Write a statement that stores 75 in row 3, column 2 of Points.
Check my answermodel answer and marking points
DECLARE Names : ARRAY[1:25] OF STRING DECLARE Points : ARRAY[1:6, 1:4] OF INTEGER Points[3, 2] ← 75
The array Colours[1:50] already holds 50 colour names. Write pseudocode to input a colour and output how many times it appears in the array, or a suitable message if it does not appear.
Check my answermodel answer and marking points
OUTPUT "Enter a colour" INPUT Colour Count ← 0 FOR Index ← 1 TO 50 IF Colours[Index] = Colour THEN Count ← Count + 1 ENDIF NEXT Index IF Count = 0 THEN OUTPUT Colour, " is not in the list" ELSE OUTPUT Colour, " appears ", Count, " times" ENDIF
- prompt + INPUT
- Count set to 0
- loop through all 50 elements
- compare element with the input, add 1
- both outputs
Complete this bubble sort so that Scores[1:20] is sorted into descending order.
Last ← REPEAT Swap ← FOR Index ← 1 TO Last - 1 IF Scores[Index] Scores[Index + 1] THEN Temp ← Scores[Index] Scores[Index] ← Scores[Index + 1] ← Temp Swap ← TRUE ENDIF NEXT Index Last ← Last - 1 UNTIL OR Last = 1
Check my answermodel answer and marking points
20FALSE<Scores[Index + 1]NOT Swap
Last ← 20 REPEAT Swap ← FALSE FOR Index ← 1 TO Last - 1 IF Scores[Index] < Scores[Index + 1] THEN Temp ← Scores[Index] Scores[Index] ← Scores[Index + 1] Scores[Index + 1] ← Temp Swap ← TRUE ENDIF NEXT Index Last ← Last - 1 UNTIL NOT Swap OR Last = 1
The 2D array Sales[1:4, 1:12] holds the monthly sales of 4 shops for 12 months (row = shop, column = month). Write pseudocode to output the total sales of each shop, then the number of the shop with the highest total.
Check my answermodel answer and marking points
BestTotal ← -1 BestShop ← 0 FOR Shop ← 1 TO 4 ShopTotal ← 0 FOR Month ← 1 TO 12 ShopTotal ← ShopTotal + Sales[Shop, Month] NEXT Month OUTPUT "Shop ", Shop, " total sales: ", ShopTotal IF ShopTotal > BestTotal THEN BestTotal ← ShopTotal BestShop ← Shop ENDIF NEXT Shop OUTPUT "Shop ", BestShop, " sold the most: ", BestTotal
- nested loops: shops outside, months inside
- shop total reset to 0 for each shop
- add Sales[Shop, Month]
- output each shop's total
- track the highest total and its shop number
- final output
File handling
Syllabus 8.3
Big ideaVariables forget everything when the program stops. A file remembers.
Data in variables and arrays is lost when the program ends. A file keeps it, so it can be used again later or by another program.
| Statement | Does |
|---|---|
OPENFILE "Scores.txt" FOR READ | open to read from it |
OPENFILE "Scores.txt" FOR WRITE | create a new file (an existing one is overwritten) |
READFILE "Scores.txt", Line | read the next line into a variable |
WRITEFILE "Scores.txt", Line | write a value as the next line |
CLOSEFILE "Scores.txt" | close it when finished |
DECLARE StudentName : STRING DECLARE Count : INTEGER OPENFILE "Names.txt" FOR WRITE FOR Count ← 1 TO 3 OUTPUT "Enter a name" INPUT StudentName WRITEFILE "Names.txt", StudentName NEXT Count CLOSEFILE "Names.txt" OPENFILE "Names.txt" FOR READ READFILE "Names.txt", StudentName OUTPUT "First name in the file: ", StudentName CLOSEFILE "Names.txt"
Your turn
Write pseudocode to input the names of 3 players and store them in a new text file Players.txt.
Check my answermodel answer and marking points
DECLARE PlayerName : STRING DECLARE Count : INTEGER OPENFILE "Players.txt" FOR WRITE FOR Count ← 1 TO 3 OUTPUT "Enter player name ", Count INPUT PlayerName WRITEFILE "Players.txt", PlayerName NEXT Count CLOSEFILE "Players.txt"
- OPENFILE … FOR WRITE
- loop 3 times with prompt + INPUT
- WRITEFILE inside the loop
- CLOSEFILE
The file Message.txt holds one line of text. Write pseudocode to read it, output it in upper case, and output the number of characters it contains.
Check my answermodel answer and marking points
DECLARE Message : STRING OPENFILE "Message.txt" FOR READ READFILE "Message.txt", Message CLOSEFILE "Message.txt" OUTPUT UCASE(Message) OUTPUT "Number of characters: ", LENGTH(Message)
- open for READ
- READFILE into a variable
- UCASE output
- LENGTH output (and close the file)
Explain why a program might store data in a file instead of only in an array.
Check my answermodel answer and marking points
Data in an array is lost when the program closes (RAM). A file stores it permanently, so it can be loaded next time the program runs or used by another program.
Trace tables and finding errors
Syllabus 7.3 · 7.7 · 7.8
Big ideaA trace table is you pretending to be the computer, one line at a time. Slow is fast here.
A trace table records every change to every variable, and every output, as you run the algorithm by hand. Rules that earn the marks:
- One column per variable, plus OUTPUT.
- Go line by line. When a variable changes, write its new value in the next free cell of its column.
- Start a new row when a column you have already written in this row changes again.
- Copy outputs exactly, text included.
- Never write a value that has not changed; blank cells are fine.
01Total ← 002Count ← 003INPUT Number04WHILE Number <> 0 DO05 IF Number > 006 THEN07 Total ← Total + Number08 Count ← Count + 109 ENDIF10 INPUT Number11ENDWHILE12OUTPUT Total / Count
| Number | Total | Count | OUTPUT |
|---|---|---|---|
| 0 | 0 | ||
| 5 | 5 | 1 | |
| -3 | |||
| 8 | 13 | 2 | |
| 2 | 15 | 3 | |
| 0 | 5 |
Purpose: it outputs the average of the positive numbers entered, stopping at 0. (The -3 is ignored.) Output 5.
Your turn
Complete the trace table for the input data 4, 9, 2, 9, 7 and state the purpose of the algorithm.
01Max ← 002Position ← 003FOR Index ← 1 TO 504 INPUT Value05 IF Value > Max06 THEN07 Max ← Value08 Position ← Index09 ENDIF10NEXT Index11OUTPUT Position, " ", Max
| Index | Value | Max | Position | OUTPUT |
|---|---|---|---|---|
Check my answermodel answer and marking points
| Index | Value | Max | Position | OUTPUT |
|---|---|---|---|---|
| 0 | 0 | |||
| 1 | 4 | 4 | 1 | |
| 2 | 9 | 9 | 2 | |
| 3 | 2 | |||
| 4 | 9 | |||
| 5 | 7 | 2 9 |
Purpose: finds the largest value and the position where it first appears. Discussion point: why is Position 2 and not 4? (> is not >=, so the second 9 does not replace the first.)
Complete the trace table for the input 4073 and describe what the algorithm does.
01INPUT Number02Total ← 003WHILE Number > 0 DO04 Digit ← MOD(Number, 10)05 Total ← Total + Digit06 Number ← DIV(Number, 10)07ENDWHILE08OUTPUT Total
| Number | Digit | Total | OUTPUT |
|---|---|---|---|
Check my answermodel answer and marking points
| Number | Digit | Total | OUTPUT |
|---|---|---|---|
| 4073 | 0 | ||
| 3 | 3 | ||
| 407 | 7 | 10 | |
| 40 | 0 | ||
| 4 | 4 | 14 | |
| 0 | 14 |
It adds up the digits of a whole number (4 + 0 + 7 + 3 = 14).
This algorithm should input 10 positive numbers and output their average and the largest number. There are four errors. Give the line number of each error and the corrected line.
01Total ← 002Largest ← 003FOR Count ← 1 TO 1004 INPUT Number05 Total ← Number06 IF Number < Largest07 THEN08 Largest ← Number09 ENDIF10NEXT Number11Average ← Total * 1012OUTPUT Average, " ", Largest
Check my answermodel answer and marking points
| Line | Correction |
|---|---|
| 05 | Total ← Total + Number |
| 06 | IF Number > Largest |
| 10 | NEXT Count |
| 11 | Average ← Total / 10 |
Total ← 0 Largest ← 0 FOR Count ← 1 TO 10 INPUT Number Total ← Total + Number IF Number > Largest THEN Largest ← Number ENDIF NEXT Count Average ← Total / 10 OUTPUT Average, " ", Largest
The 15-mark scenario question
Last question on every Paper 2 · about 30 minutes
Big ideaThe big question looks scary, but it is the same patterns you already know, put together in order.
Students get an unseen situation (rainfall records, river pollution, sports results…) with named arrays and a bullet list of requirements. They can answer in pseudocode, Python, Visual Basic or Java. It is marked with two level tables and a best-fit mark:
| Marked for | Max | Level bands | What lifts the mark |
|---|---|---|---|
| AO2: applying techniques | 9 | 1–3 · 4–6 · 7–9 | the right techniques used correctly: declarations, input, loops, selection, totalling, counting, max/min, rounding, arrays used with the given names |
| AO3: a working, complete solution | 6 | 1–2 · 3–4 · 5–6 | every requirement met, logical order, meaningful names, comments, clear output messages |
A method students can follow every time
- Tick-list (3 min). Number every bullet in the question. These become R1, R2, R3 in your head.
- Data (2 min). List every array (use the exact names given), variable and constant. Declare them all.
- Write in blocks with a comment above each: declarations → input (with validation) → processing (totals, counts, max/min, averages) → output.
- Every INPUT gets a prompt; every OUTPUT gets a message. The question always asks for this.
- Check (3 min). Go down the tick-list; find the line of code that meets each bullet.
Worked example
// ---- declarations ---- CONSTANT ClassSize ← 25 CONSTANT Tests ← 3 DECLARE StudentName : ARRAY[1:25] OF STRING DECLARE Marks : ARRAY[1:25, 1:3] OF INTEGER DECLARE Student : INTEGER DECLARE Test : INTEGER DECLARE StudentTotal : INTEGER DECLARE Average : REAL DECLARE Distinctions : INTEGER DECLARE Passes : INTEGER DECLARE Fails : INTEGER DECLARE BestAverage : REAL DECLARE BestStudent : STRING // ---- R1: input every name and mark; range check each mark ---- FOR Student ← 1 TO ClassSize OUTPUT "Enter the name of student ", Student INPUT StudentName[Student] FOR Test ← 1 TO Tests OUTPUT "Enter the mark for test ", Test, " (0 to 100)" INPUT Marks[Student, Test] WHILE Marks[Student, Test] < 0 OR Marks[Student, Test] > 100 DO OUTPUT "Invalid mark. Enter a mark from 0 to 100" INPUT Marks[Student, Test] ENDWHILE NEXT Test NEXT Student // ---- R2 + R3: total, average and result for each student ---- Distinctions ← 0 Passes ← 0 Fails ← 0 BestAverage ← -1 FOR Student ← 1 TO ClassSize StudentTotal ← 0 FOR Test ← 1 TO Tests StudentTotal ← StudentTotal + Marks[Student, Test] NEXT Test Average ← ROUND(StudentTotal / Tests, 1) OUTPUT StudentName[Student], " total: ", StudentTotal, " average: ", Average // decide and count the result IF Average >= 70 THEN OUTPUT "Result: Distinction" Distinctions ← Distinctions + 1 ELSE IF Average >= 40 THEN OUTPUT "Result: Pass" Passes ← Passes + 1 ELSE OUTPUT "Result: Fail" Fails ← Fails + 1 ENDIF ENDIF // remember the highest average so far IF Average > BestAverage THEN BestAverage ← Average BestStudent ← StudentName[Student] ENDIF NEXT Student // ---- R3: class summary ---- OUTPUT "Distinctions: ", Distinctions, " Passes: ", Passes, " Fails: ", Fails OUTPUT "Highest average: ", BestStudent, " with ", BestAverage
| Requirement | Where it is met |
|---|---|
| R1 input + validation | the first nested FOR, with the WHILE range check |
| R2 total and average | StudentTotal reset per student; ROUND(…, 1) after the inner loop |
| R3 result + counts | nested IF with three counters |
| R3 highest average | BestAverage / BestStudent updated with > |
| AO3 quality | comments on every block, constants, meaningful names, a message on every input and output |
Practice scenario (class or homework)
Check my answermodel answer and marking points
// ---- declarations ---- CONSTANT Rows ← 8 CONSTANT SeatsPerRow ← 12 CONSTANT FrontPrice ← 6 CONSTANT BackPrice ← 9 DECLARE Booked : ARRAY[1:8, 1:12] OF BOOLEAN DECLARE Row : INTEGER DECLARE Seat : INTEGER DECLARE SeatsBooked : INTEGER DECLARE Takings : INTEGER DECLARE RowCount : INTEGER DECLARE BestRow : INTEGER DECLARE BestCount : INTEGER // ---- set every seat to free ---- FOR Row ← 1 TO Rows FOR Seat ← 1 TO SeatsPerRow Booked[Row, Seat] ← FALSE NEXT Seat NEXT Row // ---- take bookings until the row entered is 0 ---- SeatsBooked ← 0 Takings ← 0 OUTPUT "Enter the row number (1 to 8), or 0 to finish" INPUT Row WHILE Row <> 0 DO IF Row < 1 OR Row > Rows THEN OUTPUT "There is no row ", Row ELSE OUTPUT "Enter the seat number (1 to 12)" INPUT Seat WHILE Seat < 1 OR Seat > SeatsPerRow DO OUTPUT "Invalid seat. Enter a seat number from 1 to 12" INPUT Seat ENDWHILE IF Booked[Row, Seat] = TRUE THEN OUTPUT "Sorry, that seat is already booked" ELSE Booked[Row, Seat] ← TRUE SeatsBooked ← SeatsBooked + 1 // price depends on the row IF Row <= 3 THEN Takings ← Takings + FrontPrice ELSE Takings ← Takings + BackPrice ENDIF OUTPUT "Row ", Row, " seat ", Seat, " is booked" ENDIF ENDIF OUTPUT "Enter the row number (1 to 8), or 0 to finish" INPUT Row ENDWHILE // ---- summary ---- OUTPUT "Seats booked: ", SeatsBooked OUTPUT "Seats free: ", Rows * SeatsPerRow - SeatsBooked OUTPUT "Total takings: $", Takings // ---- row with the most bookings ---- BestCount ← -1 BestRow ← 1 FOR Row ← 1 TO Rows RowCount ← 0 FOR Seat ← 1 TO SeatsPerRow IF Booked[Row, Seat] = TRUE THEN RowCount ← RowCount + 1 ENDIF NEXT Seat IF RowCount > BestCount THEN BestCount ← RowCount BestRow ← Row ENDIF NEXT Row OUTPUT "Row ", BestRow, " has the most seats booked (", BestCount, ")"
| Requirement | Look for |
|---|---|
| R1 set up | nested loops set all 96 elements to FALSE |
| R2 bookings | WHILE with 0 as the rogue value; row and seat validated; already-booked check; booking, count and price by row |
| R3 summary | booked, free (96 − booked) and takings output with messages |
| R3 busiest row | count per row reset to 0 for each row; max with its row number |
| AO3 | comments, constants for prices and sizes, declarations, prompts on every input |
Second scenario for homework
Check my answermodel answer and marking points
// ---- declarations (Key[1:10] is already filled) ---- DECLARE StudentName : STRING DECLARE Answer : STRING DECLARE Question : INTEGER DECLARE Score : INTEGER DECLARE Percentage : INTEGER DECLARE Students : INTEGER DECLARE ClassTotal : INTEGER DECLARE BestScore : INTEGER DECLARE BestName : STRING Students ← 0 ClassTotal ← 0 BestScore ← -1 OUTPUT "Enter the student's name, or END to finish" INPUT StudentName WHILE UCASE(StudentName) <> "END" DO // ---- mark one student's 10 answers ---- Score ← 0 FOR Question ← 1 TO 10 OUTPUT "Answer for question ", Question, " (A, B, C or D)" INPUT Answer Answer ← UCASE(Answer) WHILE Answer <> "A" AND Answer <> "B" AND Answer <> "C" AND Answer <> "D" DO OUTPUT "Invalid. Enter A, B, C or D" INPUT Answer Answer ← UCASE(Answer) ENDWHILE IF Answer = Key[Question] THEN Score ← Score + 1 ENDIF NEXT Question Percentage ← ROUND(Score / 10 * 100, 0) OUTPUT StudentName, " scored ", Score, " out of 10 (", Percentage, "%)" // ---- class totals and best student ---- Students ← Students + 1 ClassTotal ← ClassTotal + Score IF Score > BestScore THEN BestScore ← Score BestName ← StudentName ENDIF OUTPUT "Enter the student's name, or END to finish" INPUT StudentName ENDWHILE // ---- summary ---- IF Students > 0 THEN OUTPUT "Best student: ", BestName, " with ", BestScore OUTPUT "Class average: ", ROUND(ClassTotal / Students, 1), " out of 10" ELSE OUTPUT "No students were entered" ENDIF
One-page reference card
Everything students must be able to write
Big ideaEverything on one page, for the last look before the exam.
For the last five minutes of revision, or the back of an exercise book.
DECLARE Count : INTEGER DECLARE List : ARRAY[1:10] OF STRING DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR CONSTANT Rate ← 0.2 Count ← Count + 1 INPUT Name OUTPUT "Total: ", Total
IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF CASE OF Choice 1 : OUTPUT "Start" 2 : OUTPUT "Stop" OTHERWISE OUTPUT "Error" ENDCASE
FOR I ← 1 TO 10 STEP 1 OUTPUT I NEXT I WHILE Number <> 0 DO INPUT Number ENDWHILE REPEAT INPUT Age UNTIL Age > 0
PROCEDURE Greet(Name : STRING) OUTPUT "Hello ", Name ENDPROCEDURE CALL Greet("Ali") FUNCTION Square(N : INTEGER) RETURNS INTEGER RETURN N * N ENDFUNCTION X ← Square(4)
LENGTH(Word) SUBSTRING(Word, Start, Length) UCASE(Word) LCASE(Word) MOD(17, 5) DIV(17, 5) ROUND(Value, 2) RANDOM()
OPENFILE "Data.txt" FOR WRITE WRITEFILE "Data.txt", Line CLOSEFILE "Data.txt" OPENFILE "Data.txt" FOR READ READFILE "Data.txt", Line CLOSEFILE "Data.txt"
Your progress on this note is saved when JavaScript is on.