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
Procedures, Functions and Strings in Pseudocode
  1. 1Procedures, functions and parameters
  2. 2Library routines and string handling
  3. 3Maintainable programs and the long scenario question
  1. Computer Science
  2. /Procedures, Functions and Strings in Pseudocode
  3. /Maintainable programs and the long scenario question

Course 8.2·Lesson 3 of 3

Maintainable programs and the long scenario question

A program is read far more often than it is written. This lesson shows how to make pseudocode maintainable, with meaningful identifiers, comments, constants and subroutines, and how to plan and write the long scenario answer at the end of Paper 2.

about 25 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Procedures, Functions and Strings in Pseudocode
  1. 1Procedures, functions and parameters
  2. 2Library routines and string handling
  3. 3Maintainable programs and the long scenario question

Try the code and the simulations beside the lesson.

Code that someone else can read

Open an old school notebook and you may not understand your own notes. Programs are the same. A maintainable program is one that another person, or you a year later, can read, correct and change. The syllabus asks for four habits.

  • Meaningful identifiers for variables, constants, arrays, procedures and functions: AdultFare, not a.
  • Comments that say what a part of the program does: // The cost of one day of trips.
  • Constants for values that may change, such as a price, written once at the top.
  • Procedures and functions for each separate job.

Before and after

Here is a working program. Can you say what it does?

pseudocode
DECLARE A : INTEGER
DECLARE B : INTEGER
DECLARE C : REAL
INPUT A
INPUT B
C ← A * 2.40 + B * 1.20
IF C > 6.00
  THEN
    C ← 6.00
ENDIF
OUTPUT C

It works out a day of bus fares with a daily cap, but nothing tells you so. Here is the same algorithm, written to be maintained:

pseudocode
// Bus fares for one day, with a daily cap
CONSTANT AdultFare ← 2.40
CONSTANT ChildFare ← 1.20
CONSTANT DayCap ← 6.00

// The cost of one day of trips, never more than the cap
FUNCTION DayCost(AdultTrips : INTEGER, ChildTrips : INTEGER) RETURNS REAL
    DECLARE Cost : REAL
    Cost ← AdultTrips * AdultFare + ChildTrips * ChildFare
    IF Cost > DayCap
      THEN
        Cost ← DayCap
    ENDIF
    RETURN ROUND(Cost, 2)
ENDFUNCTION

DECLARE Adults : INTEGER
DECLARE Children : INTEGER
OUTPUT "Adult trips today?"
INPUT Adults
OUTPUT "Child trips today?"
INPUT Children
OUTPUT "Cost today: ", DayCost(Adults, Children)

For 1 adult trip and 2 child trips the output is Cost today: 4.8, because 2.40+2×1.20=4.802.40 + 2 \times 1.20 = 4.802.40+2×1.20=4.80. For 3 adult trips and 1 child trip the cost would be 8.408.408.40, so the cap gives Cost today: 6.0. When the fares change next year, only the three constants change. The function can be tested on its own with any two numbers. Single letters are fine only where they are a convention, such as i and j for array positions.

The long scenario question

The last question of Paper 2 gives a scenario and asks for a whole program. It is worth 15 marks. You may answer in pseudocode, Python, Visual Basic or Java. The marks are for the logic, not for the exact spelling of a language. A plan helps.

  1. Read the scenario twice. Underline every task: each input, check, calculation and output.
  2. List the data. Write the variables, constants and arrays you need, with their types.
  3. Write it in parts. Inputs and validation, then the processing, then the outputs.
  4. Use the standard methods. Totals, counts, the largest and smallest, the average and validation are all expected. Chapter 7 of this book teaches them.
  5. Comment each part. A short comment shows the examiner what the next lines do.
  6. Tick the list. Check that every task you underlined is in your program.
  7. Dry-run it with a small set of data, including one value that should be rejected.

Each task is usually worth a mark, and so are good layout and comments. A program that does most of the tasks scores well, even if one part is missing. So never leave the answer blank.

Practise with new numbers

Try it in Python

The program is the tidy bus-fare program in Python, tested with three days.

Read it first. Then run it. Which test day reaches the cap?

1. The cap goes up to 7.50 next year. Change one line so the program follows.

2. Add a comment above the three tests that says what each one checks.

Common mistakes

  • Names that say nothing, such as x, temp2 or data. Say what the value is.
  • A magic number such as 6.00 typed in several places. Use a constant.
  • Comments that repeat the code, such as // add 1 to Count. Say why, or what a part does.
  • One long block. Put each separate job in a procedure or a function.
  • In the scenario question, forgetting the outputs, or forgetting to validate the input.

Remember these

  • Maintainable: meaningful identifiers, comments, constants, procedures and functions.
  • Plan the scenario answer: tasks, data, parts, comments, a check against the list, a dry run.
  • In the scenario question you may use pseudocode, Python, Visual Basic or Java.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Give a better identifier for a variable called n that holds the number of students in a class.
  1. Why is CONSTANT VatRate ← 0.2 better than typing 0.2 in five places?
  1. In the tidy program, what is output for 0 adult trips and 4 child trips?
  1. Which part of the bus program would you put in a procedure, and why?
  1. In the scenario question, what should you do if you cannot finish one part?

Enroll free in Procedures, Functions and Strings in Pseudocode

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

This program works, but it is hard to maintain…Easy · High School (9–10) · by StemPy Lab
This function should return the larger of two integers, and the main program should output twice…Medium · High School (9–10) · by StemPy Lab
A long scenario question. A website asks each new user for a password…Hard · High School (9–10) · by StemPy Lab
That was the last lessonBack to the course
← Procedures, Functions and Strings in Pseudocode
← Library routines and string handlingNext →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place in the course.

Question Sets (1)

Procedures, Functions and Strings: Concept Check10 questions · by StemPy Lab