Random Quote Fetcher Function

  • Share this:

Code introduction


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}"                
              
Tags: