Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1data = receive_data() | AThe receive step: a function gets external data (such as from a file or API) and stores it in a variable for later steps. | |
| 2show_result(summary) | Bdef main(): data = receive_data() result = process_data(data) show_result(result) | |
| 3Each pipeline step gets its own function, and main() calls them in order: receive, process, then display. | CThe steps are out of order. process_data(data) is called before data exists, which causes a NameError. The receive step must come first. | |
| 4The process step takes the received data as a parameter and returns a new value instead of printing it. | Ddef process_data(data): return sum(data) / len(data) | |
| 5def main(): result = process_data(data) data = receive_data() show_result(result) | EThe process function prints the result instead of returning it. Displaying is the job of the display step, and nothing is passed on to show_result. | |
| 6def process_data(data): total = sum(data) print(total) | FThe display step: a function shows the processed result to the user, such as a printed summary. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
receive -> process -> display — A prototype pipeline: get external data into a variable, process it with a function, then show the result. Each step has its own function, called from main().def main():
data = receive_data()
result = process_data(data)def main():
raw = receive_data()
result = process_data(raw)def display_result(result):
print("Average:", result)def average(values):
total = sum(values)
return total / len(values)response = requests.get(URL)
raw = response.json()
result = process_data(raw)