Data exchange

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Data exchange

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which best describes data exchange?
A Transferring data between people, systems or organisations in an agreed format
B Storing data in one place on a single computer
2. A bank transfer between two banks is an example of data exchange.
A True
B False
3. Which two roles are needed for data exchange to happen?
A A compiler and an interpreter
B A sender and a receiver
4. Why must the sender and receiver agree on a format such as CSV or JSON?
A So the receiver can read and interpret the data correctly
B So the data takes up more storage space
5. Which scenario is data exchange between systems?
A A student typing notes into a document on their own laptop
B A school system sending student records to a state agency as a CSV file

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1sender -> format -> channel -> receiver AThe path of a data exchange: a sender packages data in an agreed format and sends it over a channel to a receiver
2{"from": "A", "to": "B", "amount": 50} BA bank transfer message in an agreed format (JSON) that both systems can read
3Data exchange needs an agreed format so the receiver can read what the sender sends Crequests.get("https://api.school.edu/records")
4Systems exchange data over an agreed channel, such as a web request to another system DThe sender and receiver have not agreed on a format, so the receiver cannot read the data. Both must use the same format, such as CSV.
5Sender saves data as XML, but the receiver only reads CSV EStoring data on one computer is not an exchange. A data exchange is a transfer of data between two or more people, systems or organisations.
6Data exchange is when one person keeps data stored on their own computer Fstudent_id,name,year 101,Ava,12

Definitions

data exchange

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
import json message = json._____(record)
2.
import json received = json._____(message)
3.
___ send_data(record, receiver): return json.dumps(record)
4.
if senderFormat __ receiverFormat: print("Exchange can proceed")
5.
with open("transfer.csv", "w") as f: f._____(message)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A import json
B record = {"id": 7, "amt" 50}
C text = json.dumps(record)
D print(text)
Question 2
A s_fmt = "CSV"
B r_fmt = "CSV"
C if s_fmt = r_fmt:
D print("Exchange OK")
Question 3
A def send(data, channel):
B packet = {"via": channel}
C packet["body"] == data
D return packet
Question 4
A import json
B raw = '{"name": "Ava"'
C data = json.loads(raw)
D print(data["name"])
Question 5
A header = "id,name,mark"
B row = "1;Ava;88"
C fields = row.split(",")
D print(len(fields))

Answer Key

Data exchange
Section A: Quick Questions
Q1
A — Transferring data between people, systems or organisations in an agreed format
Q2
A — True
Q3
B — A sender and a receiver
Q4
A — So the receiver can read and interpret the data correctly
Q5
B — A school system sending student records to a state agency as a CSV file
Section B: Match the Pairs
Q1
sender -> format -> channel -> receiver → The path of a data exchange: a sender packages data in an agreed format and sends it over a channel to a receiver
Q2
{"from": "A", "to": "B", "amount": 50} → A bank transfer message in an agreed format (JSON) that both systems can read
Q3
Data exchange needs an agreed format so the receiver can read what the sender sends → student_id,name,year 101,Ava,12
Q4
Systems exchange data over an agreed channel, such as a web request to another system → requests.get("https://api.school.edu/records")
Q5
Sender saves data as XML, but the receiver only reads CSV → The sender and receiver have not agreed on a format, so the receiver cannot read the data. Both must use the same format, such as CSV.
Q6
Data exchange is when one person keeps data stored on their own computer → Storing data on one computer is not an exchange. A data exchange is a transfer of data between two or more people, systems or organisations.
Section C: Definitions
Q1
data exchange — The transfer of data between people, systems or organisations, where a sender and receiver use an agreed format over an agreed channel, such as a bank transfer or sharing records.
Section D: Fill in the Blanks
Q1
import json message = json.dumps(record)
Q2
import json received = json.loads(message)
Q3
def send_data(record, receiver): return json.dumps(record)
Q4
if senderFormat == receiverFormat: print("Exchange can proceed")
Q5
with open("transfer.csv", "w") as f: f.write(message)
Section E: Spot the Error
Q1
B — A dictionary needs a colon between each key and value. It should be "amt": 50. Without it the record cannot be built into the JSON text the receiver expects.
Q2
C — A single = assigns a value. Comparing the sender's and receiver's agreed formats needs ==, so the line should be if s_fmt == r_fmt:.
Q3
C — == compares values and stores nothing, so the data is never put in the packet. It should use = to assign: packet["body"] = data.
Q4
B — The received JSON text is missing its closing brace. Because it breaks the agreed format, json.loads would fail. It should end with }.
Q5
B — The header uses commas, so the agreed CSV format means each row must also use commas. A semicolon-separated row breaks the format. It should be "1,Ava,88".