Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

these are the codes: def count_types(pokedb,pokemons): lst={} for pokemon in pokemons: pokemontype= pokedb[pokemon][0] if pokemontype in lst: lst[pokemontype]+=1 else: lst[pokemontype]=1 return lst print(count_types(Africa, pokemonLocations.txt)) Error:

image text in transcribed

these are the codes:

def count_types(pokedb,pokemons): lst={} for pokemon in pokemons: pokemontype= pokedb[pokemon][0] if pokemontype in lst: lst[pokemontype]+=1 else: lst[pokemontype]=1 return lst print(count_types("Africa", "pokemonLocations.txt"))

Error:

pokemontype= pokedb[pokemon][0] TypeError: string indices must be integers

file:

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 squirtle,water,Oceania wartortle,water,Antarctica blastoise,water,Africa,South America caterpie,bug,Oceania metapod,bug,Asia,Africa,Europe,South America butterfree,bug,Antarctica,Oceania,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 pidgeotto,flying,Europe,Asia pidgeot,flying,Europe,Oceania,Asia rattata,normal,South America,Europe,Antarctica raticate,normal,Oceania spearow,flying,South America,North America,Antarctica,Europe fearow,flying,Asia,Antarctica ekans,poison,Europe,Oceania,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,ground,Asia,South America,North America nidoranfemale,poison,Asia

Write a function called count_types () which takes as parameter(s): A dictionary in the format of the pokemon database as described in Q1 A list of pokemon names (as strings) This function should construct and return a dictionary where each key is a pokemon type (e.g. grass or fire, etc...) and the value for that key is the number of pokemon of that type in the given list of pokemon names. Recall that pokemon type was one of the fields for each pokemon record in the database. For example, using the sample list of all of the pokemon from "Africa" (see Q3 to see that list), the resulting dictionary should be: {'dragon': 1, 'rock': 4, 'normal': 4, 'flying': 3, 'fire': 1, 'electric': 2, 'bug': 3, 'ghost': 2, 'water': 9, 'poison': 6, 'fairy': 1, 'psychic': 3, 'ground: 3, grass': 2, 'fighting': 4} Also, note that this function must not change the pokemon database or the given list of pokemon names in any way. Write a function called count_types () which takes as parameter(s): A dictionary in the format of the pokemon database as described in Q1 A list of pokemon names (as strings) This function should construct and return a dictionary where each key is a pokemon type (e.g. grass or fire, etc...) and the value for that key is the number of pokemon of that type in the given list of pokemon names. Recall that pokemon type was one of the fields for each pokemon record in the database. For example, using the sample list of all of the pokemon from "Africa" (see Q3 to see that list), the resulting dictionary should be: {'dragon': 1, 'rock': 4, 'normal': 4, 'flying': 3, 'fire': 1, 'electric': 2, 'bug': 3, 'ghost': 2, 'water': 9, 'poison': 6, 'fairy': 1, 'psychic': 3, 'ground: 3, grass': 2, 'fighting': 4} Also, note that this function must not change the pokemon database or the given list of pokemon names in any way

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions