Input/Output CS Thinking Example 3
Follow the full solution, then compare it with the other examples linked below.
Example 3
mediumA 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 Step 1: Input: 5 test scores. Process: sum the scores and divide by 5. Output: the average score.
- 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
Example 1 easy
Identify the inputs and outputs in this program: name = INPUT('What is your name?'). age = INPUT('Ho
Example 2 mediumA temperature converter takes a Celsius value as input and outputs the Fahrenheit equivalent. Write
Example 4 hardDescribe three different input devices and three different output devices a computer program might u