Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Retrieve and Display Cat Facts | API Basics and Making Requests
Working with APIs in Python

bookChallenge: Retrieve and Display Cat Facts

In this challenge, you will put your skills to the test by working with a fun and straightforward public API. Your goal is to use the Cat Facts API to fetch and display three random cat facts. This exercise will give you hands-on practice making HTTP requests using the requests library and handling JSON data returned from an API. You will see how to extract specific information from the response and present it clearly to the user. By the end of this task, you will have reinforced your understanding of the basics of interacting with web APIs in Python.

Task

Swipe to start coding

Write a function that retrieves and displays three random cat facts by making three separate requests to the Cat Facts API at "https://catfact.ninja/fact". For each request, extract the cat fact from the JSON response and print it on a new line.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

What is the Cat Facts API and how do I use it?

Can you show me how to make an HTTP request with the requests library?

How do I extract and display the cat facts from the API response?

close

bookChallenge: Retrieve and Display Cat Facts

Swipe to show menu

In this challenge, you will put your skills to the test by working with a fun and straightforward public API. Your goal is to use the Cat Facts API to fetch and display three random cat facts. This exercise will give you hands-on practice making HTTP requests using the requests library and handling JSON data returned from an API. You will see how to extract specific information from the response and present it clearly to the user. By the end of this task, you will have reinforced your understanding of the basics of interacting with web APIs in Python.

Task

Swipe to start coding

Write a function that retrieves and displays three random cat facts by making three separate requests to the Cat Facts API at "https://catfact.ninja/fact". For each request, extract the cat fact from the JSON response and print it on a new line.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3
single

single

some-alt