Home > Mobile >  setting min and max price from API variable in function
setting min and max price from API variable in function

Time:11-27

I have an API web enter image description here

import requests
import json

def fun(minprice,maxprice):
    for i in range(0,10):
        response= requests.get("http://www.boredapi.com/api/activity/")
        content_dict=json.loads(response.content)
        del(content_dict['key'])
        del(content_dict['link'])
        del(content_dict['participants'])
        del(content_dict['accessibility'])
        minprice=content_dict['price']
        maxprice=content_dict['price']
        print(content_dict)
fun(0,0.1)

CodePudding user response:

Hello from what I understand you are trying to go though each option and check if the price is between two values you can do this by check if the price is between your values like this assuming that content_dict['price'] is a float

if content_dict['price'] > minprice and content_dict['price'] < maxprice:
    # whatever you want
  • Related