How do I see how much the function returns Python

-1

I made a script that returns me the names of online players of a given game Only I wanted to put the amount. How would this structure for quantity return be? I have already tried to create a list and with it use the len plus error function.

import requests
import json

def Expert_serve():

    serve = "expert"
    url = requests.get('http://infinite-flight-public-api.cloudapp.net/v1/Flights.aspx?apikey=78879b1d-3ba3-47de-8e50-162f35dc6e04&sessionid=7e5dcd44-1fb5-49cc-bc2c-a9aab1f6a856')
    response = url.json()
    for i in range(100):              
        if "IFATC" in response[i]["DisplayName"]:
            print(response[i]['DisplayName'])



teste = (Expert_serve())

print ('Jogadores online {}'.fotmat (len(teste))

    
asked by anonymous 23.01.2018 / 20:37

1 answer

2

This is because your program is not returning players, just by printing their names. You can put together a list (in the example done with list understanding ), use it as a function return , to get its size:

import requests
import json

def Expert_serve():    
    serve = "expert"
    url = requests.get('http://infinite-flight-public-api.cloudapp.net/v1/Flights.aspx?apikey=78879b1d-3ba3-47de-8e50-162f35dc6e04&sessionid=7e5dcd44-1fb5-49cc-bc2c-a9aab1f6a856')
    response = url.json()
    listaDeJogadores = [response[i]["DisplayName"] for i in range(100) if  "IFATC" in response[i]["DisplayName"]]
    return listaDeJogadores


lista = Expert_serve()
print("Lista de jogadores: ", lista)    
print ('Jogadores online: ',len(lista))
    
23.01.2018 / 21:14