Vivian Kim
Vivian Kim

Reputation: 13

Python API calling+ for loops

Hi I am trying to call API and get a growth rate of poke API. I am sort of stuck now and return experience += 1 part gives me syntax error as well. Can you drop me a hint? Or how I should approach?

I intended to get each level & experience level from the first function then calculate the growth rate at the second function, the first part works but I got stuck at the second part.

import json
import requests
import pandas as pd
import matplotlib.pyplot as plt


def get_growth_rate(rate):
    request1=requests.get(rate)
    loaded1= json.loads(request1.content)

    try:
        descriptions,formula,id_1,levels,name,pokemon_species = loaded1.values()
        return levels

    except IndexError:
        return None
        pass
    
def plot_growth_rate(levels):
    experience=[]
    levels[0],levels[1] = get_growth_rate(rate)
    for i in level[0]:
        return experience += 1
                
    growth_rate = (experience[i+1]-experience[i]/experience[i])) * 100
    get_growth_rate("https://pokeapi.co/api/v2/growth-rate/5")

Upvotes: 0

Views: 62

Answers (1)

I159
I159

Reputation: 31199

return experience += 1 is syntactically incorrect, as it said. To do it, you need two lines:

experience += 1
return experience

Or if the experience is a local variable and you don't need to use it after the function returned, it is return experience + 1.

The loop with return without any conditions doesn't make any sense.

Upvotes: 2

Related Questions