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.

Past paper questionPearson 1CP2/02June 2022 Paper 210 marksComplete the program

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.pi produces it.
  • radius * 2 for radius squared. Squared is ** 2. Times two is the diameter.
  • diameter >= side as 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.

12 and 8 give Invalid input. 10 and 4 give 49.73451754256331. Try 10 and 5: the circle just fits.
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)
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

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

  1. F1.9 Arithmetic operators Programming basics
  2. F4.5 Libraries and your own modules Functions and structured code
  3. F6.1 Defensive design and validation Robust programs
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.