Make random advice generator using python

No need to take anyone advice if you know python create your own advice generator

So here we will see how we can create our own random advice generator using python,so for this i am going to use https://api.adviceslip.com/ API from adviceslip so now we will see the steps how we can make our own random advice generator

Step no.1

As we are going to deal with API so firstly we need to install requests library,just open terminal and type below command

pip install requests

So now we will use this library

import requests

So now the second step

Step no. 2

url = “https://api.adviceslip.com/advice”

def randomadvice():

   Data = requests.get(url)

   json_data = Data.json()

   random_advice = json_data[“slip”]

   print(random_advice[“advice”])

randomadvice()

Here we have created one url variable and stored API url and in the next line we have created the main function where we are fetching the data from ADVICESLIP api , So we have created one Data variable where we are storing the response which we will get from url and than we need to convert that into JSON format , Just need to print that ,at the end just we have called the function,

Here the structure of data

Full code:

output:

You can also refer video tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *