Edexcel GCSE Computer Science June 2024 Paper 2, Question 4: the cafe order

Pearson Edexcel 1CP2/02 June 2024, Question 4: turn a flowchart into a Python program that works out the crisps, cheese and rolls to order for adults and children, rounding up with math.ceil and using the given constants. A model answer and the fifteen marks.

Past paper questionPearson 1CP2/02June 2024 Paper 215 marksWrite a program

Question 4 of the Pearson Edexcel GCSE Computer Science Paper 2 sat on 21 May 2024 (1CP2/02) gives you a flowchart and asks for the Python. It is worth 15 marks. The flowchart is long, but it is only arithmetic and two decisions, and the constants you need are already in the file.

We do not copy the exam paper or Pearson's code files here. Open the paper beside this page: Edexcel June 2024 Paper 2 question paper (PDF). When you have finished, check the mark scheme too.

The question in short

A cafe caters for events. Each adult needs 0.75 of a bag of crisps, 40 grams of cheese and 1.5 rolls. Each child needs 0.33 of a bag, 30 grams and 0.5 of a roll. Crisps come in whole bags. Cheese comes in 500 gram packs. Rolls come in packs of 24.

The flowchart: get the adults and children. Work out the partial bags of crisps, display them, round up to whole bags and display that. Work out the grams of cheese; if it is no more than one pack, say "order one pack of cheese", otherwise display the packs to order. Work out the rolls; if it is no more than one pack, say "order one pack of rolls", otherwise display the packs.

Rounding up

Every "determine whole ... to order" box means round up. 8.49 bags of crisps is 9 bags: you cannot buy 0.49 of a bag, and 8 is not enough. Python's rounding up is math.ceil(). round() goes to the nearest, and int() chops down. Both give the wrong order.

A model answer

import math

CRISPS_PER_ADULT = 0.75
CRISPS_PER_CHILD = 0.33
CHEESE_PER_ADULT = 40
CHEESE_PER_CHILD = 30
ROLLS_PER_ADULT = 1.5
ROLLS_PER_CHILD = 0.5
MIN_CHEESE = 500
MIN_ROLLS = 24

numAdults = int(input("How many adults? "))
numChildren = int(input("How many children? "))

# crisps
bagsCrisps = numAdults * CRISPS_PER_ADULT + numChildren * CRISPS_PER_CHILD
print("Partial bags of crisps required:", bagsCrisps)
print("Whole bags of crisps to order:", math.ceil(bagsCrisps))

# cheese
gramsCheese = numAdults * CHEESE_PER_ADULT + numChildren * CHEESE_PER_CHILD
if gramsCheese <= MIN_CHEESE:
    print("Order one pack of cheese")
else:
    print("Packs of cheese to order:", math.ceil(gramsCheese / MIN_CHEESE))

# rolls
numRolls = numAdults * ROLLS_PER_ADULT + numChildren * ROLLS_PER_CHILD
print("Partial number of rolls required:", numRolls)
if numRolls <= MIN_ROLLS:
    print("Order one pack of rolls")
else:
    print("Packs of rolls to order:", math.ceil(math.ceil(numRolls) / MIN_ROLLS))

Where the fifteen marks are

Twelve single marks: two integer inputs in two variables; the crisps calculation; the cheese calculation; an if/else for cheese; the rolls calculation; an if/else for rolls; <= in both tests; informative messages (at least five of the nine in the flowchart); white space and comments; the given constants used throughout; a syntactically correct rounding expression; and math.ceil() used correctly.

Then up to 3 for how well it runs. The paper's test data: 10 adults and 3 children need 8.49 bags (order 9), 490 grams (one pack), and 16.5 rolls (one pack).

Where the marks are lost

  • round() or int() to get whole bags. 8.49 would give 8 bags, and 3 people would go without.
  • Typing 0.75 and 40 into the sums. A mark is for using the constants throughout.
  • < for <=. Exactly 500 grams is one pack, not two.
  • Nothing between the two inputs and the sums. Comments and blank lines are a mark.
  • Skipping the "partial" displays. The flowchart shows them, and messages are marked.

Run it

Enter the adults and children. The robot's light goes green when the order is worked out.

10 adults and 3 children: 8.49 bags so order 9, one pack of cheese, one pack of rolls. 45 and 14: order 39 bags, 5 packs of cheese and 4 packs of rolls.
The program
from bugbot import *
import math
connect()

CRISPS_PER_ADULT = 0.75
CRISPS_PER_CHILD = 0.33
CHEESE_PER_ADULT = 40
CHEESE_PER_CHILD = 30
ROLLS_PER_ADULT = 1.5
ROLLS_PER_CHILD = 0.5
MIN_CHEESE = 500
MIN_ROLLS = 24

numAdults = int(input("How many adults? "))
numChildren = int(input("How many children? "))

# crisps: whole bags, rounded up
bagsCrisps = numAdults * CRISPS_PER_ADULT + numChildren * CRISPS_PER_CHILD
print("Partial bags of crisps required:", bagsCrisps)
print("Whole bags of crisps to order:", math.ceil(bagsCrisps))

# cheese: 500 g packs
gramsCheese = numAdults * CHEESE_PER_ADULT + numChildren * CHEESE_PER_CHILD
if gramsCheese <= MIN_CHEESE:
    print("Order one pack of cheese")
else:
    print("Packs of cheese to order:", math.ceil(gramsCheese / MIN_CHEESE))

# rolls: packs of 24
numRolls = numAdults * ROLLS_PER_ADULT + numChildren * ROLLS_PER_CHILD
print("Partial number of rolls required:", numRolls)
if numRolls <= MIN_ROLLS:
    print("Order one pack of rolls")
else:
    print("Packs of rolls to order:", math.ceil(math.ceil(numRolls) / MIN_ROLLS))
led("green")
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

How do I round up in Python?

Import math and use math.ceil(value). It returns the smallest whole number that is not less than the value, so math.ceil(8.49) is 9 and math.ceil(8.0) is 8.

How do I turn a flowchart into Python?

Take the boxes in order. A parallelogram is an input or a print. A rectangle is a calculation or an assignment. A diamond is an if, with the Yes branch under the if and the No branch under the else.

Why does the program use constants for the amounts?

If a portion size changes, only the constant at the top changes. The mark scheme gives a mark for using the constants in every calculation and comparison.

More from this paper

Every Edexcel 1CP2 question we have worked

Learn it step by step

  1. F5.2 Flowcharts Algorithms
  2. F4.5 Libraries and your own modules Functions and structured code
  3. F1.6 Variables, constants and assignment Programming basics
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.