Input/Output CS Thinking Example 3

Follow the full solution, then compare it with the other examples linked below.

Example 3

medium
A program reads a list of 5 test scores and outputs the average. Identify the inputs, process, and output. What type of validation might you add to the input?

Solution

  1. 1
    Step 1: Input: 5 test scores. Process: sum the scores and divide by 5. Output: the average score.
  2. 2
    Step 2: Input validation: check that each score is a number, within a valid range (e.g., 0-100), and that exactly 5 scores are entered.

Answer

Input: 5 scores. Process: sum / 5. Output: average. Validate that scores are numbers between 0 and 100.
Input validation ensures the program receives sensible data before processing. Without it, invalid inputs could cause errors or incorrect results.

About Input/Output

The mechanisms by which a program receives data from the outside world (input) and sends results back (output). Input can come from keyboards, files, sensors, or network connections; output can go to screens, files, printers, or other devices.

Learn more about Input/Output โ†’

More Input/Output Examples