promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

talking to apis — the call ai makes 100 times a day — step 8 of 8

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.

Final drill. Below is a function fetch that simulates an API call — it returns a (status_code, body) tuple. Write a function safe_fetch that:

  • Calls fetch(user_id).
  • If the status is 200, returns body["name"].
  • For any other status, returns the string "error".

Then the script will call safe_fetch(7) and safe_fetch(404) and print both. Expected output:

maya
error

full-screen editor opens — close anytime to keep reading.