Edexcel GCSE Computer Science sample Paper 2, Question 5: the volume of a cone
Pearson Edexcel 1CP2/02 sample assessment material, Question 5: complete a subprogram that returns the volume of a cone from its radius and height, call it from the main program, and print the result to three decimal places. The fifteen marks explained, with the program to run.
Question 5 of Pearson's sample assessment material for Edexcel GCSE Computer Science Paper 2 (1CP2/02) is 15 marks for a formula, a subprogram that returns it, and a formatted output. Eleven of the marks are for the pieces of a well-made function.
We do not copy the paper or Pearson's code files here. Open the paper beside this page: Edexcel 1CP2/02 sample assessment materials (PDF). The mark scheme is in the same document.
The question in short
The volume of a cone is one third of pi times the radius squared times the height. A program and a subprogram have been started. The subprogram must work for any radius and height passed as parameters and calculate the volume. The main program must print the volume to three decimal places, such as 16.135.
The file names the parameters pRadius and pHeight, the result inside the subprogram theVolume, and the main program's variables baseRadius, coneHeight and coneVolume.
A finished program
import math
def calculateVolume(pRadius, pHeight):
theVolume = (1 / 3) * math.pi * pRadius ** 2 * pHeight
return theVolume
baseRadius = float(input("Radius: "))
coneHeight = float(input("Height: "))
coneVolume = calculateVolume(baseRadius, coneHeight)
print("{:.3f}".format(coneVolume))
Where the fifteen marks are
Eleven single marks: import math; two parameters in the definition; named pRadius and pHeight; the formula translated correctly; math.pi used; both parameters used in the calculation; the result assigned to theVolume; one return with theVolume; the call passing baseRadius and coneHeight; in the same order as the definition; the returned value stored in coneVolume; and the volume formatted to three decimal places for output only. Then up to 3 for functionality.
Where the marks are lost
- Rounding the stored value.
round(coneVolume, 3)changes the number, and Python drops trailing zeros when it prints, so 16.1 stays 16.1. The question wants three places every time, which needs string formatting:"{:.3f}".format(...). 1 / 3in Python 2 style. In Python 3,1 / 3is 0.333. Fine. But1 // 3is 0, and so is the volume.pRadius * 2. Squared is** 2.printinside the subprogram. It must return.- Parameters swapped in the call. The call must pass the radius first, to match the definition.
Run it
Enter a radius and a height. The robot's light goes green when the volume is printed.
The program
from bugbot import *
import math
connect()
def calculateVolume(pRadius, pHeight):
theVolume = (1 / 3) * math.pi * pRadius ** 2 * pHeight
return theVolume
baseRadius = float(input("Radius: "))
coneHeight = float(input("Height: "))
coneVolume = calculateVolume(baseRadius, coneHeight)
print("{:.3f}".format(coneVolume))
led("green")
Questions
What is the answer to Edexcel sample Paper 2 Question 5?
Import math. Define the subprogram with pRadius and pHeight, set theVolume to (1 / 3) * math.pi * pRadius ** 2 * pHeight and return it. Call it with baseRadius and coneHeight, store the result in coneVolume, and print it with "{:.3f}".format(coneVolume).
How do I print a number to three decimal places in Python?
print("{:.3f}".format(value)), or an f-string: print(f"{value:.3f}"). Unlike round(), this always shows three places, including trailing zeros.
Why use parameters instead of reading the inputs inside the subprogram?
So the subprogram works for any values it is given, from any part of the program, and can be tested on its own. The mark scheme gives a mark for using the two parameters in the calculation.
More from this paper
Every Edexcel 1CP2 question we have worked
Learn it step by step
- F4.2 Parameters and return values Functions and structured code
- F4.5 Libraries and your own modules Functions and structured code
- F1.9 Arithmetic operators 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.