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. /A car park charges by the whole hour. This pseudocode works out the charge in dollars…
MediumComputer ScienceHigh School (9–10)Computer Science › ProgrammingNumericalIGCSE

A car park charges by the whole hour. This pseudocode works out the charge in dollars…

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.

A car park charges by the whole hour. This pseudocode works out the charge in dollars.

pseudocode
DECLARE Hours : INTEGER
DECLARE Charge : INTEGER
INPUT Hours
IF Hours <= 1
  THEN
    Charge ← 0
  ELSE
    IF Hours <= 4
      THEN
        Charge ← 2 * Hours
      ELSE
        Charge ← 8 + 3 * (Hours - 4)
    ENDIF
ENDIF
OUTPUT Charge

Dry-run the program for the inputs 1, 3 and 6. What is the output each time?

Check your answer

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

Need a reminder? The key ideaShowHide

IF <condition> then THEN, an optional ELSE, and ENDIF; THEN and ELSE are two spaces in. CASE OF <identifier> lists single values, each with one statement, tested in order; OTHERWISE comes last; ENDCASE closes it. Relational operators: =, <, <=, >, >=, <>. Logical: AND, OR, NOT.

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.

Input 1. 1 <= 1 is TRUE, so Charge ← 0. The output is 0.

Input 3. 3 <= 1 is FALSE, so we go to the ELSE. There 3 <= 4 is TRUE, so Charge ← 2 * 3 = 6. The output is 6.

Input 6. Both tests are FALSE, so Charge ← 8 + 3 * (6 - 4) = 8 + 6 = 14. The output is 14.

Check. At 4 hours the middle rule gives 2×4=82 \times 4 = 82×4=8, and the last rule starts at 888. The charge never jumps down, which is what a car park wants.

Answer: 0, 6 and 14 dollars.

Log in to save this for later
← All Problems
← A café screen shows three meals: 1 for soup, 2 for pasta and 3 for salad…A youth club accepts members aged 11 to 16, both included. A programmer wrote… →
More onComputer Science › Programming

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Selection with IF and CASEVariables, Selection and Loops in Pseudocode

More on this topic

  1. A long scenario question. A teacher has the names of 5 students in the file Names.txt, one name a…Hard
  2. Shopping.txt holds six lines: bread, rice, milk, eggs, tea and jam…Medium
  3. The file Best.txt holds one line: 120. What is output, and what does Best.txt hold afterwards, when…Easy
The nine squares of a board are input row by row: X, O, O, then X, X, X, then O, a dot for an empty…Hard
  • Three teams play three games each. Points[Team, Game] holds the points of a team in a game…Medium
  • All problems on this topic →