HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /This is the kind of long scenario question that ends Paper 2…
HardComputer ScienceHigh School (9–10)Computer Science › Algorithms and Problem-SolvingcodingConceptualIGCSE

This is the kind of long scenario question that ends Paper 2…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

This is the kind of long scenario question that ends Paper 2. In the exam you may answer in pseudocode, Python, Visual Basic or Java. Here, write pseudocode.

A car park has 404040 spaces. A sensor at the gate sends the input IN when a car enters and OUT when a car leaves. At the end of the day the attendant inputs END. Write an algorithm that:

  • starts with no cars in the car park;
  • adds one car for IN and takes one car away for OUT;
  • outputs an error message for any other input;
  • outputs the number of free spaces after each input;
  • outputs FULL when there are no free spaces left;
  • after END, outputs how many cars came in during the day.

Use meaningful names and add comments. Then work out what your algorithm outputs at the end for the inputs IN, IN, OUT, IN, IN, END.

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

Flowchart symbols: terminator (START, STOP), process (rectangle), input/output (parallelogram), decision (diamond, two exits Yes and No), subroutine (rectangle with a line inside each end), flow line (arrow). A flow line back to an earlier shape makes a loop. Conditions are written precisely, such as Count > 10.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Plan. Two counters, a constant for the size of the car park, and a loop that runs until END.

A model answer.

pseudocode
// Car park counter
CONSTANT Spaces ← 40
Cars ← 0                 // cars in the car park now
CarsIn ← 0               // cars that came in today
INPUT Signal
WHILE Signal <> "END" DO
    IF Signal = "IN"
      THEN
        Cars ← Cars + 1
        CarsIn ← CarsIn + 1
      ELSE
        IF Signal = "OUT"
          THEN
            Cars ← Cars - 1
          ELSE
            OUTPUT "Error: input IN, OUT or END"
        ENDIF
    ENDIF
    OUTPUT "Free spaces: ", Spaces - Cars
    IF Cars = Spaces
      THEN
        OUTPUT "FULL"
    ENDIF
    INPUT Signal
ENDWHILE
OUTPUT "Cars in today: ", CarsIn

The run. After IN, IN, OUT, IN, IN there are 1+1−1+1+1=31 + 1 - 1 + 1 + 1 = 31+1−1+1+1=3 cars inside, so the free spaces are 40−3=3740 - 3 = 3740−3=37. Four inputs were IN, so the output at the end is Cars in today: 4.

A marking list. A teacher would give one mark for each point like these.

  1. A constant or a variable for the 404040 spaces.
  2. The counter of cars inside starts at 000.
  3. The counter of cars in today starts at 000.
  4. A loop that stops when END is input.
  5. An input inside the loop (and one before it, for a pre-condition loop).
  6. IN adds 111 to the cars inside.
  7. IN also adds 111 to the cars in today.
  8. OUT takes 111 from the cars inside.
  9. Any other input gives an error message.
  10. The free spaces, Spaces - Cars, are worked out.
  11. The free spaces are output after each input.
  12. FULL is output when the cars inside equal the spaces.
  13. The cars in today are output after the loop.
  14. Meaningful names, used the same way throughout.
  15. Comments that say what the parts do.

Answer: 373737 free spaces after the last car, and 444 cars came in.

What if? A careful answer also refuses IN when the car park is full, and refuses OUT when it is empty. Add AND Cars < Spaces to the first test and AND Cars > 0 to the second.

Log in to save this for later
← All Problems
← A flowchart inputs two numbers, A and B…A garden centre sells turf by the square metre… →
More onComputer Science › Algorithms and Problem-Solving

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. FlowchartsPlanning a Program: Life Cycle, Decomposition and Flowcharts

More on this topic

  1. A delivery company adds a check digit to each parcel number…Medium
  2. Name the check in each case. Say whether it is validation or verification…Easy
  3. A bubble sort is changed so that it sorts in descending order: the comparison becomes IF…Hard
A shop stores the colours of the ten bicycles in its window in an array Colours: red, blue, red…Medium
  • A bubble sort puts the scores 5, 1, 4, 2, 8 into ascending order…Medium
  • All problems on this topic →