Edexcel GCSE Computer Science June 2022 Paper 2, Question 3: the excess card
Pearson Edexcel 1CP2/02 June 2022, Question 3: complete a Python program that checks a circle fits inside a square and works out the area of card left over, using math.pi. The ten marks explained, and the program to run with the paper's test data.
Question 3 of the Pearson Edexcel GCSE Computer Science Paper 2 from the June 2022 series (1CP2/02) is a 10 mark "translate the formulae into Python" question, with one validation check in it.
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
A circle is cut out of a square of card. The program works out the area of card left over.
- The user inputs the length of the square's side and the radius of the circle, both integers.
- The circle's diameter (2 x radius) must be the same size as the side, or smaller. If not, the input is invalid.
- Area of a square is side squared. Area of a circle is pi times radius squared.
- The variables supplied in the file must be used.
The paper gives two tests: a side of 12 with a radius of 8 is invalid, and a side of 10 with a radius of 4 gives 49.73451754256331.
A finished program
import math
side = 0
radius = 0
diameter = 0
squareArea = 0.0
circleArea = 0.0
excessArea = 0.0
side = int(input("Length of side: "))
radius = int(input("Radius of circle: "))
diameter = 2 * radius
if diameter > side:
print("Invalid input")
else:
squareArea = side ** 2
circleArea = math.pi * radius ** 2
excessArea = squareArea - circleArea
print(excessArea)
Where the ten marks are
Seven are for single things: importing the math library; initialising circleArea to a real number (0.0); the diameter calculation; a relational test between diameter and side; the area of the square; ** 2 for the radius squared; and the subtraction.
Three are for how well it runs with the test data. Using the constant math.pi, not 3.14, is one of the things that is looked for.
Where the marks are lost
- 3.14 for pi. The expected output has 14 decimal places. Only
math.piproduces it. radius * 2for radius squared. Squared is** 2. Times two is the diameter.diameter >= sideas invalid. The question says the diameter may be the same size. Only bigger is invalid. (The mark scheme lets this go, but your test of 10 and 5 would fail.)circleArea = 0. The question wants a real number:0.0.- New variable names. The variables supplied must be used.
Run it
Type the side and the radius. The robot's light is red for invalid input.
The program
from bugbot import *
import math
connect()
side = int(input("Length of side: "))
radius = int(input("Radius of circle: "))
diameter = 2 * radius
if diameter > side:
led("red")
print("Invalid input")
else:
squareArea = side ** 2
circleArea = math.pi * radius ** 2
excessArea = squareArea - circleArea
led("green")
print(excessArea)
Questions
What is the answer to Edexcel GCSE Computer Science 2022 Paper 2 Question 3?
Import math. Input side and radius as integers. Set diameter to 2 * radius. If diameter is greater than side, print Invalid input. Otherwise print side ** 2 minus math.pi * radius ** 2.
How do I use pi in Python?
Put import math at the top of the program and use math.pi. It is more accurate than typing 3.14, and examiners look for it.
How do I square a number in Python?
Use the power operator: radius ** 2. math.pow(radius, 2) and radius * radius work as well.
More from this paper
Every Edexcel 1CP2 question we have worked
Learn it step by step
- F1.9 Arithmetic operators Programming basics
- F4.5 Libraries and your own modules Functions and structured code
- F6.1 Defensive design and validation Robust programs
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.