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 | |
|---|---|---|
| 1import requests | ALoads the third-party requests library so the program can send web requests | |
| 2response = requests.get(url) | Bstatus_code is an integer, so comparing it to the string "200" is never true. It should be compared to the number 200. | |
| 3Pass extra parameters to an API by giving requests.get() a params dictionary | CSends a request to the API endpoint and stores the returned response object in a variable | |
| 4Check that the request succeeded before using the data (200 means success) | Dif response.status_code == 200: | |
| 5response = requests.get(url) # no import requests at the top | Erequests.get(url, params={"city": "Melbourne"}) | |
| 6if response.status_code == "200": | FThe requests library was never imported, so Python raises a NameError because requests is not defined. Add import requests at the top. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
requests.get(url) — Sends a request to a web API endpoint at the given URL and returns a response object. Needs import requests. Check response.status_code (200 means success) before using the data.import requestsresponse = requests.get(url)params = {"city": "Melbourne"}
r = requests.get(url, params=params)url = "https://api.example.com/data"
r = requests.get(url)if r.status_code == 200:
data = r.json()