Practice question · Put in order
Order the structured approach to the task: read a list of exam scores and report how many passed and the class average.
- Handle the edge cases, such as an empty list
- Package the repeated logic in a function such as average(scores)
- Test with typical, empty, all-passing, and boundary inputs
- Model the data: the scores are a list of numbers
- Sketch the algorithm in pseudocode, looping over the scores
Hints
- Modelling the data comes before sketching the algorithm that operates on it.
- Edge-case handling and testing come after the core logic is packaged.
Show the answer
- Model the data: the scores are a list of numbers
- Sketch the algorithm in pseudocode, looping over the scores
- Package the repeated logic in a function such as average(scores)
- Handle the edge cases, such as an empty list
- Test with typical, empty, all-passing, and boundary inputs
Why
Model the data, sketch the algorithm, package it in a function, guard the edge cases, then test. This is the shape of nearly all beginner programming, the concepts are assembled in this order, not applied one isolated trick at a time.
Practise Integrated Introductory Programming Practice
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Integrated Introductory Programming Practice
- Select every input that should be in the test suite for the passing-and-average task.
- A program that counts passing scores needs a loop, a conditional and an accumulator, and removing any one of…
- A beginner writes a working program and cannot explain why it works. Why is that a problem even though the…
- Passing is a score of 50 or more. Sort each score by whether it passes or fails.