OCR GCSE Computer Science June 2025 Paper 2, Question 6(e): the ticket booking loop
OCR J277/02 June 2025, Question 6(e): complete an algorithm that starts with 500 tickets, takes bookings, refuses one that is too big, and repeats until no tickets are left. Model answers, the greater than or equal trap, the six marks explained, and the program to run.
Question 6(e) is the last question of the OCR GCSE Computer Science Paper 2 sat on 20 May 2025 (J277/02): 6 marks, in OCR Exam Reference Language or a high-level language. The first line, tickets = 500, is given. You write a loop with a decision inside it.
We do not copy the exam paper here. Open it beside this page: OCR June 2025 J277/02 question paper (PDF). When you have finished, check the mark scheme too.
The question in short
There are 500 tickets, stored in the variable tickets. Complete the algorithm to:
- ask the user how many tickets they would like, and take that as input;
- if there are enough, output "Tickets booked" and reduce
tickets; - if there are not enough, output "Not enough tickets";
- repeat until there are no tickets left.
A model answer
In OCR Exam Reference Language:
tickets = 500
while tickets > 0
wanted = int(input("How many tickets would you like?"))
if wanted <= tickets then
print("Tickets booked")
tickets = tickets - wanted
else
print("Not enough tickets")
endif
endwhile
In Python:
tickets = 500
while tickets > 0:
wanted = int(input("How many tickets would you like? "))
if wanted <= tickets:
print("Tickets booked")
tickets = tickets - wanted
else:
print("Not enough tickets")
The trap: exactly enough
If 5 tickets are left and someone wants 5, the booking must go through. So the test is wanted <= tickets, with the equals sign. With a plain <, the last tickets can never be sold to someone who wants all of them, and the mark scheme checks for exactly this.
Where the six marks are
- inputting the number of tickets wanted, and storing it;
- checking whether there are enough tickets left;
- the two messages, the right way round;
- reducing
ticketscorrectly; - an attempt at a loop;
- repeating it all while tickets are left (
while tickets > 0, oruntil tickets == 0).
Where the marks are lost
tickets = 500inside the loop. The stock is reset on every pass and the tickets never run out. The mark scheme refuses the last mark for this.- The input outside the loop. Then the same booking is repeated for ever. Each pass needs a new input.
tickets = wanted - tickets. The wrong way round. It istickets - wanted.- A
forloop. Nobody knows how many bookings it will take. - Reducing
ticketsin both branches. A refused booking sells nothing.
Run it
This version starts with 20 tickets so that you can sell out quickly. The robot's light is green for a booking and red for a refusal, and it drives forward as the tickets go.
The program
from bugbot import *
connect()
# the exam starts with 500. 20 is quicker to sell
tickets = 20
while tickets > 0:
print(tickets, "tickets left")
wanted = int(input("How many tickets would you like? "))
if wanted <= tickets:
led("green")
print("Tickets booked")
tickets = tickets - wanted
forward(60, distance=wanted)
else:
led("red")
print("Not enough tickets")
print("Sold out")
Now change it
Ask for -5 tickets. The booking succeeds and the stock goes up. Add validation so that a booking must be for at least 1 ticket.
Answer
Change the test to wanted >= 1 and wanted <= tickets, or add a loop after the input that asks again while wanted is less than 1.Questions
What is the answer to OCR J277 June 2025 Paper 2 Question 6(e)?
While tickets is greater than 0: input how many tickets are wanted. If that is less than or equal to tickets, print Tickets booked and subtract it from tickets. Otherwise print Not enough tickets.
Why is it less than or equal to, and not less than?
Because a booking for exactly the number of tickets left should succeed. With less than, a customer wanting the last 5 tickets when 5 remain would be refused.
Where should a variable be initialised when it is used in a loop?
Before the loop. If it is set inside the loop it is reset on every pass, and any change made by the previous pass is lost.
More from this paper
- Question 5(d): Validate a 4 character PIN that must not be 1234 or 4321 6 marks
- Question 6(a): Input two passwords and check that they match 4 marks
- Question 6(c): Write a function that returns a ticket price, then call it 6 marks
Every OCR J277 question we have worked
Learn it step by step
- F2.6 Condition-controlled loops: while Decisions and loops
- F2.7 Loop patterns Decisions and loops
- F13.4 Programming questions Exam preparation
This is our own explanation of a published exam question. It is not written or endorsed by OCR, and the question paper and mark scheme remain OCR's copyright. Read them on OCR's site with the links on this page.