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.

Past paper questionPearson 1CP2/02June 2025 Paper 215 marksRearrange the lines

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

  1. Constants and variables first, before anything runs: the four constants (ZERO, THREE, FOUR, FIVE) and the three variables.
  2. The input is the first line of the main program.
  3. The while loop comes after that input.
  4. The length check (if len(inString) >= THREE) is the first thing inside the loop.
  5. total is reset to 0 before the for loop over the characters.
  6. The for loop is inside the while and inside the if.
  7. Inside the for: convert the character to its ASCII value, then add it to the total.
  8. if, elif, else for the divisibility checks, in that order, each with its own concatenation under it.
  9. The print comes after all three concatenations.
  10. else with the error message matches the length check.
  11. 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 total outside the while. The second string would start from the first string's total.
  • The else for the length check attached to the divisibility if. Watch the indentation: the error message lines up with the outer if.
  • 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.

cup gives 328 cup4, snow gives 455 snow5, Ian gives 280 Ian4, HAT gives 221 HAT0. X is too short. Enter nothing to stop.
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: ")
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

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

Every Edexcel 1CP2 question we have worked · Guide: Logic gates and truth tables explained

Learn it step by step

  1. F3.2 Character codes and conversion Strings, lists and records
  2. F2.3 else, elif and Boolean operators Decisions and loops
  3. F2.6 Condition-controlled loops: while Decisions and loops
Open the lessons

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.