Skip to content

Instantly share code, notes, and snippets.

@IT102Gists
Last active April 17, 2022 08:09
Show Gist options
  • Save IT102Gists/2c142ed70286b0ad948c0924796e6fb0 to your computer and use it in GitHub Desktop.
Save IT102Gists/2c142ed70286b0ad948c0924796e6fb0 to your computer and use it in GitHub Desktop.
Fetch a random joke from the Internet Chuck Norris Database (ICNDb) with Python 3 and Requests.
# Learn more about the ICNDb API at: http://www.icndb.com/api/
# Learn more about the Requests library at: http://docs.python-requests.org/en/master/
import requests
def get_joke():
"""fetches and prints a random joke"""
url = "http://api.icndb.com/jokes/random"
resp = requests.get(url)
data = resp.json()
print(data["value"]["joke"])
get_joke()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment