Practice Input/Output in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
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.
What goes in and what comes out. Keyboard โ program โ screen.
Showing a random 20 of 50 problems.
Example 1
mediumA user is asked for a positive number. They enter . Name two ways robust I/O code should respond.
Example 2
mediumA temperature converter takes a Celsius value as input and outputs the Fahrenheit equivalent. Write pseudocode and identify the input, process, and output.
Example 3
mediumA program expects a number but the user types `abc`. What should robust I/O code do?
Example 4
easyA program writes results to a file instead of the screen. Is the file input or output here?
Example 5
easyA program reads a temperature from a sensor and turns on a fan. Identify input, process, and output.
Example 6
mediumA program reads three integers and prints their sum. Trace with inputs 4, 7, 9.
Example 7
mediumTrace: input='12', x=int(input); input='5', y=int(input); print(x*y).
Example 8
medium`print("A"); x = read(); print("B")`. The user sees `A`, the program waits, then after typing shows `B`. Why the pause?
Example 9
mediumA program prints a prompt but the cursor stays on the next line before input. What output detail controls staying on the same line?
Example 10
easyA program reads from the keyboard and shows results on the screen. Which is input and which is output?
Example 11
easyName the device category: a touchscreen acts as both ___ and ___.
Example 12
easyFill in the blank: A program transforms ___ into output.
Example 13
challengeASCII encodes 'A' as 65. A program reads the character 'A'. How many bits minimally store one standard ASCII character, and how many distinct characters fit?
Example 14
easyBesides the keyboard, name one source a program can read input from.
Example 15
hardA log file grows unbounded as a program runs. What output strategy prevents disk exhaustion?
Example 16
mediumA buffered output is not appearing on screen even though `print` ran. What concept explains this?
Example 17
easyA user types `42` at a keyboard prompt. By default, what data type does the program receive?
Example 18
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?
Example 19
hardTrace: a program prints 5 lines, but stdout is piped to 'head -n 3'. How many lines does the user see?
Example 20
challengeA program reads 1000 lines one-at-a-time vs reading the whole file then processing. Why might line-at-a-time be preferred for a 50 GB file?