Skip to content

Instantly share code, notes, and snippets.

@jonathanhle
Last active October 13, 2023 04:05
Show Gist options
  • Save jonathanhle/37120d326223597bfac2d6ca99b1a403 to your computer and use it in GitHub Desktop.
Save jonathanhle/37120d326223597bfac2d6ca99b1a403 to your computer and use it in GitHub Desktop.
PokeAPI-based Coding Test Practice

PokeAPI-based Coding Test Practice

Environment:

  • Programming Language: Python (or your preferred language)
  • Libraries allowed: requests, json

Problem 1: Basic API Request (Easy)

Problem Statement:

Write a function called get_pokemon_name that takes a Pokemon ID and returns the name of the Pokemon.

def get_pokemon_name(pokemon_id: int) -> str:
    pass

Problem 2: Extracting Multiple Data (Easy)

Problem Statement:

Given a Pokemon name, write a function called get_pokemon_info to retrieve the following details:

  • Name
  • Base experience
  • Height
  • Weight

The function should return a dictionary.

def get_pokemon_info(pokemon_name: str) -> dict:
    pass

Problem 3: Digging Deeper (Medium)

Problem Statement:

Some Pokemon have multiple types (e.g., Water, Grass). Write a function called get_pokemon_types that retrieves all types for a given Pokemon.

def get_pokemon_types(pokemon_name: str) -> list:
    pass

Problem 4: Handling Relationships (Medium)

Problem Statement:

Pokemons evolve from one form to another. Write a function called get_evolution_chain that retrieves the entire evolution chain for a given Pokemon.

Hint: You might need to explore the evolution-chain endpoint.

def get_evolution_chain(pokemon_name: str) -> list:
    pass

Problem 5: Data Aggregation (Medium)

Problem Statement:

Given a type of Pokemon (e.g., 'Water'), write a function called average_base_experience to calculate the average base experience for all Pokemon of that type.

def average_base_experience(pokemon_type: str) -> float:
    pass

Problem 6: Advanced Filtering (Hard)

Problem Statement:

Write a function called filter_pokemon that retrieves all Pokemon below a given height and weight and sorts them by their base experience in descending order.

def filter_pokemon(height: int, weight: int) -> list:
    pass

Bonus Problem: Asynchronous Calls (Very Hard)

Problem Statement:

Fetching each Pokemon's details sequentially can be time-consuming. Write an asynchronous function called async_get_pokemon_details that takes in a list of Pokemon names and retrieves their details concurrently.

You might want to use asyncio and aiohttp for this task.

async def async_get_pokemon_details(pokemon_names: list) -> list:
    pass
@jonathanhle
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment