Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this is my code: def read _ pokedata ( poke _ file ) : poke _ file = open ( poke _ file, ' r
this is my code: def readpokedatapokefile:
pokefile openpokefile, r
pokedata
takes parameter pokefile and returns a dictionary of the records of each pokemon with
pokemon name as the key and data as its value
pokefile: file consisting of pokemons name, type and location
for line in pokefile:
# split any newline characters in the file
spaces line.strip
# separate each value that has a comma and turn it into list
items spaces.split
# name, type and location based on the indexes of the list
pokemonname items
pokemontype items
pokemonlocation joinitems:
# pokemon name as the key with separate dictionary of pokemon type and locations as value
pokedatapokemonnamepokemon type': pokemontype, 'locations: pokemonlocation
return pokedata
#pokedata readpokedatapokefile
def findcontinentspokedata:
defines function findcontinents with parameter pokedata and returns list of different
locations pokemon's can be found in
pokedata: dictionary consisting of pokemon name its key and separate dictionary with type and locations as value
# for pokemon name and data within that name turn the values within data into list
continentlist
for name, data in pokedata.items:
# for each continent in the second index of that value locations
for location in datalocationssplit:
# append unique continent into continentlist if its not already in the list
if location.strip not in continentlist:
continentlist.appendlocationstrip
return continentlist
def pokemonincontinentpokedata, continentlist:
takes function pokemonincontinent and returns list of pokemons in every continent within continent list
pokedata: dictionary of pokemon name with pokemon type and location
contentlist: list of continents pokemons are in
continentpokemons
# for each continent in continent list and each name and data in dictionary
# if the continent is in the 'locations of a specific pokemon, append that pokemon name in continentpokemons list
for continent in continentlist:
for name, data in pokedata.items:
if continent in datalocations:
continentpokemons.appendname
return continentpokemons
def counttypespokedata, continentpokemons:
defines function counttypes with two parameters and returns dictionary of number of types within each continent
pokedata: takes dictionary of pokedata
continentpokemons: takes list of pokemons present in the continent
poketypes
# for each pokemon in continentpokemons list
for pokemon in continentpokemons:
pokemontype pokedatapokemonpokemon type'
# if the pokemon type is in poketypes update it by
if pokemontype in poketypes:
poketypespokemontype
# if the pokemon type is not in poketypes count it by
else:
poketypespokemontype
return poketypes
pokedata readpokedatapokefile
continents findcontinentspokedata
# for each continent in continents
for continent in continents:
# defines variable that takes all pokemons inesting Part readpokedata: Since this function reads data from a file, your test inputs must
in fact consist of different files! Thus, for each test, create an input file with the same format as
pokemonLocations.txt Your test files will likely be MUCH smaller than the provided file. Do not bother
testing with files that are not correctly formatted, focus instead on the diversity of possible valid files.
Testing Part findcontinents: The inputs to this function is a database of Pokemon information.
It is ok to use your readpokedata function to create the database rather than typing in database
literals so long as you confident that function works thanks to testing it in which case your test inputs
will again consist of input files. Careful! The pokemon in your database might be processed in any
order because its a dictionary! and we dont care about the ORDER of the continents in the resulting
list. You can deal with this by SORTING the resulting list before comparing it to the expected result!
Testing Part pokemonincontinent: Again this function requires a database, and it is again ok
to use your readpokedata funtion to create it if you find this less tedious. The continent name for
each test should however be picked manually. And again, youll want to sort the resulting list before
testing.
Testing Part counttypes: Again this function requires a database, and it is again ok to use your
readpokedata funtion to create it if you find this less tedious. The list of pokemon names should be created manually.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started