- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreqAPI.py
More file actions
Latest commit
26 lines (19 loc) · 667 Bytes
/
Copy pathreqAPI.py
File metadata and controls
26 lines (19 loc) · 667 Bytes
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
# How to connect to API
importrequests
base_url="https://pokeapi.co/api/v2/"
defget_pokemon_info(name):
url=f"{base_url}/pokemon/{name}"
response=requests.get(url)
ifresponse.status_code==200:
pokemon_data=response.json()
returnpokemon_data
else:
print(f"Failed to retreive data. Status code: {response.status_code}")
# print(response)
pokemon_name="pikachu"
pokemon_info=get_pokemon_info(pokemon_name)
ifpokemon_info:
print(f"Name: {pokemon_info["name"]}")
print(f"Id: {pokemon_info["id"]}")
print(f"Height: {pokemon_info["height"]}")
print(f"Weight: {pokemon_info["weight"]}")