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

medium
A user is asked for a positive number. They enter โˆ’3-3. Name two ways robust I/O code should respond.

Example 2

medium
A temperature converter takes a Celsius value as input and outputs the Fahrenheit equivalent. Write pseudocode and identify the input, process, and output.

Example 3

medium
A program expects a number but the user types `abc`. What should robust I/O code do?

Example 4

easy
A program writes results to a file instead of the screen. Is the file input or output here?

Example 5

easy
A program reads a temperature from a sensor and turns on a fan. Identify input, process, and output.

Example 6

medium
A program reads three integers and prints their sum. Trace with inputs 4, 7, 9.

Example 7

medium
Trace: 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

medium
A 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

easy
A program reads from the keyboard and shows results on the screen. Which is input and which is output?

Example 11

easy
Name the device category: a touchscreen acts as both ___ and ___.

Example 12

easy
Fill in the blank: A program transforms ___ into output.

Example 13

challenge
ASCII 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

easy
Besides the keyboard, name one source a program can read input from.

Example 15

hard
A log file grows unbounded as a program runs. What output strategy prevents disk exhaustion?

Example 16

medium
A buffered output is not appearing on screen even though `print` ran. What concept explains this?

Example 17

easy
A user types `42` at a keyboard prompt. By default, what data type does the program receive?

Example 18

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?

Example 19

hard
Trace: a program prints 5 lines, but stdout is piped to 'head -n 3'. How many lines does the user see?

Example 20

challenge
A 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?