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 = response.json() | Aresponse = requests.get(url) data = response.json() | |
| 2print(data['name']) | Bfor item in data['results']: print(item['title']) | |
| 3Looping over a list of results in the JSON data so each item can be read by key | CDictionary values from response.json() must be read with square brackets and a key, not with dot notation. | |
| 4After calling the API, convert the JSON response to Python data before reading any keys | DReads the value stored under the key 'name' in the dictionary created from the JSON | |
| 5data = response.json print(data['name']) | EConverts the JSON text of the API response into a Python dictionary or list stored in data | |
| 6data = response.json() print(data.name) | Fresponse.json is missing its brackets, so it stores the method itself instead of calling it and the JSON is never converted. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
response.json() — Converts the JSON text of an API response into Python dictionaries and lists, so you can read values by key, e.g. data['name'], or loop over a list of results.response = requests.get(url)
data = response.json()data = response.json()
name = data['name']data = response.json()
for item in data['results']:
print(item['name'])data = response.json()
total = len(data['results'])data = response.json()
first = data['results'][0]
print(first['name'])