Skip to content

Commit 6748036

Browse files
committed
#20 - Python
1 parent e210c6f commit 6748036

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
###############################################################################
2+
### EJERCICIO
3+
###############################################################################
4+
import requests
5+
6+
response = requests.get('https://api.github.com')
7+
8+
if response.status_code == 200:
9+
print('Respuesta exitosa!')
10+
content = response.json()
11+
for line in content:
12+
print(f'\n{line} : {content[line]}')
13+
else:
14+
print('Error')
15+
16+
17+
###############################################################################
18+
### DIFICULTAD EXTRA
19+
###############################################################################
20+
21+
22+
def pokemon_info(pokemon):
23+
url = f'https://pokeapi.co/api/v2/pokemon/{pokemon.lower()}'
24+
r = requests.get(url)
25+
content = r.json()
26+
27+
print('Nombre: ',content['name'].capitalize())
28+
print('Id: ', content['id'])
29+
print('Peso: ',content['weight'])
30+
print('Altura: ',content['height'])
31+
32+
types = []
33+
for indice in range(0, len(content['types'])):
34+
types.append(content['types'][indice]['type']['name'].capitalize())
35+
print('Tipo: ', ', '.join(types))
36+
37+
url_species = content['species']['url']
38+
r_species = requests.get(url_species)
39+
species = r_species.json()
40+
41+
url_evolution_chain = species['evolution_chain']['url']
42+
r_evolution = requests.get(url_evolution_chain)
43+
evolution_chain = r_evolution.json()
44+
45+
current_chain = evolution_chain['chain']
46+
evolves = []
47+
while current_chain:
48+
evolves_to = current_chain['evolves_to']
49+
if evolves_to:
50+
for evolution in evolves_to:
51+
evolves.append(evolution['species']['name'].capitalize())
52+
current_chain = evolves_to[0]
53+
else:
54+
break
55+
print('Evoluciones:', ", ".join(evolves))
56+
57+
games = []
58+
for indice in range(0, len(content['game_indices'])):
59+
games.append(content['game_indices'][indice]['version']['name'])
60+
print('Juegos en los que aparece: ', ', '.join(games))
61+
62+
63+
64+
pokemon = input('Introduce un pokemon: ')
65+
pokemon_info(pokemon)

0 commit comments

Comments
 (0)