-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpokemon.py
More file actions
26 lines (22 loc) · 795 Bytes
/
pokemon.py
File metadata and controls
26 lines (22 loc) · 795 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
# pokeapi
import requests
import json
# API endpoint
base_url = "https://pokeapi.co/api/v2/"
def get_pokemon_data(pokemon_name):
url = f"{base_url}/pokemon/{pokemon_name.lower()}"
response = requests.get(url)
if response.status_code == 200:
pokeData= response.json()
print(json.dumps(pokeData, indent=4))
return pokeData
else:
print(f"Error: {response.status_code} - {response.text}")
# Example usage
pokemon_name = input("Enter the name of the Pokémon: ")
pokemon_data = get_pokemon_data(pokemon_name)
if pokemon_data:
# Do something with the Pokémon data
print(f"Pokémon Name: {pokemon_data['name']}")
print(f"Height: {pokemon_data['height']}")
print(f"Weight: {pokemon_data['weight']}")