python:  def typehelper(poke_name):     """     Question 5 - API     Now that you've acquired a new helper, you want to take care of them!     Use the provided API to find the type(s) of the Pokemon whose name is     given. Then, for each type of the Pokemon, map the name of the type to     a list of all types that do double damage to that type.     Note: Each type should be considered individually.     Base URL: https://pokeapi.co/     Endpoint: api/v2/pokemon/{poke_name}     You will also need to use a link provided in the API response.     Args:         Pokemon name (str)     Returns:         Dictionary of types     Hint: You will have to run requests.get() multiple times!     >>> typehelper("bulbasaur")         {'grass': ['flying', 'poison', 'bug', 'fire', 'ice'], 'poison': ['ground', 'psychic']}     >>> typehelper("corviknight")         {'flying': ['rock', 'electric', 'ice'], 'steel': ['fighting', 'ground', 'fire']}     """ # pprint(typehelper("bulbasaur")) # pprint(typehelper("corviknight"))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

python: 

def typehelper(poke_name):
    """
    Question 5 - API

    Now that you've acquired a new helper, you want to take care of them!
    Use the provided API to find the type(s) of the Pokemon whose name is
    given. Then, for each type of the Pokemon, map the name of the type to
    a list of all types that do double damage to that type.
    Note: Each type should be considered individually.

    Base URL: https://pokeapi.co/

    Endpoint: api/v2/pokemon/{poke_name}

    You will also need to use a link provided in the API response.

    Args:
        Pokemon name (str)

    Returns:
        Dictionary of types

    Hint: You will have to run requests.get() multiple times!

    >>> typehelper("bulbasaur")
        {'grass': ['flying', 'poison', 'bug', 'fire', 'ice'], 'poison': ['ground', 'psychic']}

    >>> typehelper("corviknight")
        {'flying': ['rock', 'electric', 'ice'], 'steel': ['fighting', 'ground', 'fire']}

    """

# pprint(typehelper("bulbasaur"))
# pprint(typehelper("corviknight"))

Expert Solution
Code process

To help you take care of your new helper, this code can be used to find the type(s) of a Pokemon whose name is given. It uses the provided API to send a request to the given endpoint and retrieves the type of the Pokemon. It then maps the name of the type to a list of all types that do double damage to that type. 

The code starts by importing the `requests` library, which enables the sending and retrieval of data from the API. The `pprint` library is also imported to print the output in a readable format.

Then, a function called `typehelper` is defined that takes in the name of the Pokemon as an argument. It starts by building the base URL and endpoint with the Pokemon's name. Then, a `GET` request is sent to the API, and the response is stored in a variable as a dictionary.

To iterate over the Pokemon's types and map them to the list of all types that do double damage to them, a `for` loop is used. It runs through the dictionary, and for each type, it again sends a `GET` request to the API, retrieves the double damage list and stores it in a new variable.

Finally, the `pprint` library is used to print the output in a readable format. This code can be used to take care of your helper and check out the types of Pokemon.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education