Last active
October 30, 2022 00:00
-
-
Save fmasanori/1288160dad16cc473a53 to your computer and use it in GitHub Desktop.
World Cup in six lines of Python 3. Jogos da Copa do Mundo em cinco linhas de Python 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
jogos = requests.get('http://worldcup.sfg.io/matches').json() | |
for jogo in jogos: | |
if jogo['status'] in ('completed', 'in progress'): | |
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', | |
jogo['away_team']['country'], jogo['away_team']['goals']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No meu Python so rodou assim (dei um espaço na terceira linha):
import urllib.request
import json
resp = urllib.request.urlopen ('http://worldcup.sfg.io/matches').read()
for jogo in json.loads(resp.decode('utf-8')):
if jogo['status'] == 'completed':
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', jogo['away_team']['country'], jogo['away_team']['goals'])