-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
mouredev.py
59 lines (46 loc) · 1.61 KB
/
mouredev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests
"""
Ejercicio
"""
response = requests.get("https://google.com")
if response.status_code == 200:
print(response.text)
else:
print(f"Error con código {response.status_code} al realizar la petición.")
"""
Extra
"""
pokemon = input("Introduce un nombre o número del Pokémon a buscar: ").lower()
response = requests.get(f"https://pokeapi.co/api/v2/pokemon/{pokemon}/")
if response.status_code == 200:
data = response.json()
print("Nombre: ", data["name"])
print("ID: ", data["id"])
print("Peso: ", data["weight"])
print("Altura: ", data["height"])
print("Tipo(s): ")
for type in data["types"]:
print(type["type"]["name"])
print("Juegos:")
for game in data["game_indices"]:
print(game["version"]["name"])
response = requests.get(
f"https://pokeapi.co/api/v2/pokemon-species/{pokemon}/")
if response.status_code == 200:
url = response.json()["evolution_chain"]["url"]
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print("Cadena de evolución:")
def get_evolves(data):
print(data["species"]["name"])
if "evolves_to" in data:
for evolve in data["evolves_to"]:
get_evolves(evolve)
get_evolves(data["chain"])
else:
print(f"Error {response.status_code} obteniendo las evoluciones.")
else:
print(f"Error {response.status_code} obteniendo las evoluciones.")
else:
print(f"Error {response.status_code}: Pokémon no encontrado")