0

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")
4
  • Please post the full error Commented Nov 28, 2020 at 16:00
  • You can't return experience += 1. Because it is indeed invalid syntax Commented Nov 28, 2020 at 16:02
  • The code is not clear and contains multiple syntax issuse. Commented Nov 28, 2020 at 16:13
  • In your own words, what do you think return experience += 1 should do? Commented Nov 28, 2020 at 16:15

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.