Edexcel GCSE Computer Science June 2022 Paper 2, Question 1: numbers to letters
Pearson Edexcel 1CP2/02 June 2022, Question 1: amend a Python program so that it turns a number from 5 to 30 into a capital letter by adding 60 and using chr(), with a range check and an error message. The ten marks explained, and the program to run.
Question 1 of the Pearson Edexcel GCSE Computer Science Paper 2 from the June 2022 series (1CP2/02, Application of Computational Thinking) is the warm-up of the on-screen paper: 10 marks, one for each small thing you add to a half-written Python file.
We do not copy the exam paper or Pearson's code files here. Open the paper beside this page: Edexcel June 2022 Paper 2 question paper (PDF). When you have finished, check the mark scheme too.
The question in short
The program turns a number into a letter. Only 5 to 30 is valid. Adding 60 to the number gives an ASCII code, and chr() turns that code into a capital letter. So 5 gives 65, which is A, and 30 gives 90, which is Z. Anything else displays an error message.
You open the given file and amend it to: create an integer variable num set to 0; take the input and convert it to an integer; check the range; add 60 and store the result in decimalCode; join strings with concatenation; and display an error message.
A finished program
num = 0
decimalCode = 0
num = int(input("Enter a number: "))
if num >= 5 and num <= 30:
decimalCode = num + 60
print(str(num) + " is equal to " + chr(decimalCode))
else:
print("Invalid input")
Where the ten marks are
One each for: num = 0; an input with a prompt; int() round it; the lower bound test; the upper bound test; and joining them; the addition of 60; the assignment to decimalCode; concatenation with + in the output; and a sensible error message.
Where the marks are lost
orforand. Every number is either at least 5 or at most 30, so withornothing is ever invalid.- A comma in the print. The question says join strings together with concatenation, which means
+. And+needsstr(num), because a number cannot be joined to text. num == 0. Two equals signs compare. Creating the variable needs one.- Adding extras. The paper says do not add any additional functionality. A loop that asks again is not wanted.
- Forgetting to save under the new name. The file must be saved as the name the paper gives, or nothing is marked.
Test it with the table in the paper: 4, 5, 22, 30 and 31. Two of those are invalid, two are boundaries.
Run it
Type a number. The robot's light is green for a letter and red for invalid input.
The program
from bugbot import *
connect()
num = 0
decimalCode = 0
num = int(input("Enter a number: "))
if num >= 5 and num <= 30:
decimalCode = num + 60
led("green")
print(str(num) + " is equal to " + chr(decimalCode))
else:
led("red")
print("Invalid input")
Questions
What is the answer to Edexcel GCSE Computer Science 2022 Paper 2 Question 1?
Set num to 0, read it with int(input()), test num >= 5 and num <= 30, set decimalCode to num + 60, print str(num) + " is equal to " + chr(decimalCode), and print Invalid input otherwise.
What does chr() do in Python?
It turns an ASCII (Unicode) code number into its character, so chr(65) is "A". ord() goes the other way: ord("A") is 65.
How is Edexcel Paper 2 different from AQA and OCR?
It is sat on a computer. You are given Python files to fix, finish or write, you can run your code as often as you like, and you save each answer as a new file. It is 2 hours and 75 marks.
More from this paper
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
- F1.8 Data types and casting Programming basics
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.