You can download this code by clicking the button below.
This code is now available for download.
This function calls an API to fetch a random quote and its author, and returns it.
Technology Stack : requests
Code Type : Function
Code Difficulty : Intermediate
import random
import requests
def fetch_random_quote():
url = 'https://api.quotable.io/random'
response = requests.get(url)
data = response.json()
quote = data['content']
author = data['author']
return f"{quote} - {author}"