Edexcel GCSE Computer Science June 2025 Paper 2, Question 3: ASCII totals, lines mixed up
Pearson Edexcel 1CP2/02 June 2025, Question 3: put the mixed-up lines in order so that the program adds the ASCII values of a string of three or more characters and appends 4, 5 or 0 depending on divisibility, looping until an empty input. The fifteen marks and the program to run.
Question 3 of the Pearson Edexcel GCSE Computer Science Paper 2 sat on 20 May 2025 (1CP2/02) is the 15 mark "rearrange the lines" question. All the lines are given, indented correctly, in the wrong order. Marks are for sequence only.
We do not copy the exam paper or Pearson's code files here. Open the paper beside this page: Edexcel June 2025 Paper 2 question paper (PDF). When you have finished, check the mark scheme too.
The question in short
The user enters a string. If it is shorter than three characters, an error is shown and it is not processed. Otherwise the ASCII values of its characters are added up. If the total divides by four, a 4 is added to the end of the string. Otherwise if it divides by five, a 5 is added. Otherwise a 0 is added. The total and the changed string are displayed. The program repeats until the user enters nothing.
Check one by hand: "cup" is 99 + 117 + 112 = 328, which divides by 4, so the output is 328 cup4.
The order that earns the marks
- Constants and variables first, before anything runs: the four constants (
ZERO,THREE,FOUR,FIVE) and the three variables. - The input is the first line of the main program.
- The
whileloop comes after that input. - The length check (
if len(inString) >= THREE) is the first thing inside the loop. totalis reset to 0 before theforloop over the characters.- The
forloop is inside thewhileand inside theif. - Inside the
for: convert the character to its ASCII value, then add it to the total. if,elif,elsefor the divisibility checks, in that order, each with its own concatenation under it.- The print comes after all three concatenations.
elsewith the error message matches the length check.- The second input is the last line of all.
A finished program
ZERO = "0"
THREE = 3
FOUR = 4
FIVE = 5
inString = ""
total = 0
asciiValue = 0
inString = input("Enter a string: ")
while inString != "":
if len(inString) >= THREE:
total = 0
for character in inString:
asciiValue = ord(character)
total = total + asciiValue
if total % FOUR == 0:
inString = inString + str(FOUR)
elif total % FIVE == 0:
inString = inString + str(FIVE)
else:
inString = inString + ZERO
print(total, inString)
else:
print("String must be three or more characters long")
inString = input("Enter a string: ")
Where the fifteen marks are
Thirteen for sequence, matching the list above: the declarations first; input first in the main program; while after it; the length check after the input; total reset before the for; the for inside the while; conversion inside the for; the addition after the conversion; if, elif, else in order; each concatenation inside its own branch; the print after all three; the length if paired with its else; the input last. Then one for indentation that does not cause an error, and one for working with the test data.
Where the marks are lost
- Resetting
totaloutside thewhile. The second string would start from the first string's total. - The
elsefor the length check attached to the divisibilityif. Watch the indentation: the error message lines up with the outerif. - The final input inside the
if. Then a short string ends the program instead of asking again. - Moving nothing in a section. No marks are given for a section where the given order was left alone.
- Retyping lines. Copy and paste keeps the indentation exactly.
Run it
Type strings. An empty line ends it.
The program
from bugbot import *
connect()
ZERO = "0"
THREE = 3
FOUR = 4
FIVE = 5
inString = ""
total = 0
asciiValue = 0
inString = input("Enter a string: ")
while inString != "":
if len(inString) >= THREE:
total = 0
for character in inString:
asciiValue = ord(character)
total = total + asciiValue
if total % FOUR == 0:
inString = inString + str(FOUR)
elif total % FIVE == 0:
inString = inString + str(FIVE)
else:
inString = inString + ZERO
print(total, inString)
else:
print("String must be three or more characters long")
inString = input("Enter a string: ")
Questions
Why does a total that divides by both four and five get a 4?
Because the if for four is tested first. When it is true, the elif for five is never reached. Order in an if elif chain decides which of two true conditions wins.
How do I add up the ASCII values of a string?
Set a total to 0, loop over each character, and add ord(character) to the total.
Why must the total be reset inside the while loop?
Each string needs its own total. If the reset were before the while loop, the second string's characters would be added on top of the first string's total.
More from this paper
- Question 1: Fix nine errors in a program that discounts a restaurant bill 9 marks
- Question 2: A rocket countdown with validation and time.sleep 10 marks
- Question 4: Write a multiplication square to a file with commas 11 marks
- Question 5: Draw lines and nine coloured circles with turtle graphics 15 marks
- Question 6: Validate keys with a check digit and signal readings, with a subprogram 15 marks
Every Edexcel 1CP2 question we have worked · Guide: Logic gates and truth tables explained
Learn it step by step
- F3.2 Character codes and conversion Strings, lists and records
- F2.3 else, elif and Boolean operators Decisions and loops
- F2.6 Condition-controlled loops: while Decisions and loops
This is our own explanation of a published exam question. It is not written or endorsed by Pearson, and the question paper and mark scheme remain Pearson's copyright. Read them on Pearson's site with the links on this page.