Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Before starting this question, first, download the data file pokemonLocations.txt from the class Moodle Make sure to put it in the same folder as your

image text in transcribedimage text in transcribed

Before starting this question, first, download the data file pokemonLocations.txt from the class Moodle Make sure to put it in the same folder as your a5.py python code Write a function called read_pokedata) that takes as parameter(s) . a string indicating the name of a pokemon location data file This function should return a database (i.e. a dictionary-of-dictionaries) that stores all of the Pokemon data in a format that we will describe further below. You can review section 111.9 of the text for a refresher on what databases look like using dictiona ries. Input File Format The data file for this question looks Like this: bulbasaur, grass,South America ivysaur,grass, Asia,Antarctica Each line of the file contains all of the data for a single pokemon. The first item on the line is always the pokemon's name; names are guaranteed to be unique. The second item is always the pokemon's type, which in the example above, is the type grass.1 Following that are one or more continents where that pokemon can be found. So Bulbasaur can only be found in South America, but Ivysaur can be found in both Asia and Antarctica. Note that the continent names CAN contain spaces. All of the data items on a each line are separated by commas Database Format Your function should open the file given as a parameter and read the data from it into a database. The keys for this database will be pokemon names, and the values will be records (ie another dictionary) for the matching pokemon. First, the read_pokedata) function should create an empty dictionary to be the overall database Then, for each pokemon from the input file, create one record (i.e. one dictionary) with the following fields: . The . The pokemon's type, as a string . The locations where the pokemon can be found, as a list of strings. pokemon's name, as a string This record should then be added to the database, using the pokemon's name as a key. Once all of the records have been added, the function should return the database dictionary. bulbasaur,grass,South America ivysaur.grass.Asia.Antarctica venusaur.grass.Africa,South America charmander.fire.North America,Oceania charmeleon,fire,South America charizard,fire,Oceania squirt le,water,Oceania war e,water,Antarctica blastoise.water.Africa,South. America caterpie,bug,0ceania metapod.bug.Asia.Africa.Europe.South. America butterfree,bug,Antarctica,0ceania,South America weedle,bug,Europe,South America,Asia kakuna,bug,South America,Oceania,Africa,North America beedrill,bug,North America, Asia,Oceania,Antarctica pidgey,flying,Antarctica,Europe,Oceania, South America Ridgeotto.fling.Europe.Asia pidgeot.flying.Europe,Oceania,Asia rattata.normal.South. America, Europe, Antarctica raticate,normal,Oceania spearow, f-Wing,South. America,North America,Antarctica, Europe ekans,poison,Europe,0ceania,North America, Asia arbok,poison,South America pikachu,electric,North America,Oceania,Africa raichu,electric,North America sandshrew.ground,Asia,North America, South America sandslash.qround,Asia,South America,North America nidoranfemale,poison,Asia

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions