Question: Python code, Python code, Python code. Overview Pokemon are fantastic creatures that people can catch and train. Pokemon are classified into different 'types such as


Python code, Python code, Python code.





Overview Pokemon are fantastic creatures that people can catch and train. Pokemon are classified into different 'types such as grass, fire or electric. To catch different types of pokemon, you might have to travel all over the world! For this assignment, you will build a program that will help organize information about where to go to catch the different pokemon. This assignment is divided into 5 different questions', but in the end, your work from all of the questions will be combined to complete the overall program. The first four questions will each ask you to define a function that will perform a specific task. Make sure that the inputs (parameters) and outputs (return values) of your functions match the problem description exactly, or else the whole thing won't fit together properly! The following is a brief overview of how the questions for this assignment will fit together: Question 1 Read data about the pokemon from a text file and organize it as a database. You must fully complete this question before moving on. All of the other questions will depend on the database that you create here. Question 2: Build a list of all the unique co Question 3: Build a list of all the pokemon that can be found on a particular continent. Question 4: Count how many of each pokemon type occur within a given list of pokemon names. Question 5: For each continent, display the pokemon type counts. ntinents where you can find pokemon. Individually, none of these questions are particularly difficult, but if you make a mistake anywhere along the way, then the last part won't work. Make sure to perform simple testing, such as printing out lists or dictionaries. as you go to make sure that everything looks right. One last note of caution: we have given you an input file for this assignment, but be aware that we might test your program on a different input file. Therefore, you must make sure your code is fully general; don't count on knowing exactly how many pokemon there are, or on knowing exactly what the names of the pokemon types or locations might be Question 1 (6 points) Purpose: To practice the concept of dictionary as a database Degree of Difficulty: Moderate 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 11.19 of the text for a refresher on what databases look like using dictionaries. 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 grass1 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 i.e 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 pokemon's name, as a string The pokemon's type, as a string. . The locations where the pokemon can be found, as a list of strings. 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. Question 2 (4 points): Purpose: To practice iterating over nested Degree of Difficulty: Easy. Write a function called find_continents) which takes as parameter(s): A dictionary in the format of the pokemon database as described in O1 This function should construct and return a list of all the different continents where it is possible to find pokemon. Each entry in the list should be unique: in other words, don't add the same continent twice even if you can find multiple kinds of pokemon there. For the input file you were given, the resulting list should be (though not necessarily in this order: ['0ceania', 'Asia', 'South America', 'North America', 'Africa', Antarctica', 'Europe '] Also, note that this function must not change the pokemon database in any way. Question 3 (4 points): Purpose: To practice iterating over nested compound data and accessing different dictionary fields Degree of Diffculty: Easy Write a function called pokemon_in_continent ) which takes as parameterls): A dictionary in the format of the pokemon database as described in Q1 The name of a continent, as a string The function should construct and return a list containing the names of all of the pokemon that can be found on the given continent. For example, for the input file you were given, if the continent is "Africa" the resulting List should be (though not necessarily in this order) ['gyarados', 'nidorina''magmar', 'jigglypuff 'machoke', 'machamp', 'dragonair', 'slowbro ', 'machop'venomoth', 'tentacruel', 'parasect' omanyte''polivrath', 'muk', 'hitmonlee''vaporeon', 'tangela', 'gengar' nidoranmale', 'venusaur 'onix ','nidoking', 'golem', 'aerodactyl' tauros' 'metapod', 'electrode', 'lapras'psyduck','blastoise, 'nidoqueen' 'alakazam', 'cubone', 'magikarp 'kabutops', kakuna, oliwag', 'marowak' 'rhydon', 'kangaskhan', 'zubat', 'dodrio', 'persian', 'pikachu ', 'meouth', 'drouzee','gastly' Also, note that this function must not change the pokemon database in any way. Question 4 (4 points): Purpose: To practice summarizing data from a dictionary Degree of Difficulty: Moderate 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 Question 5 (5 points) Purpose: To practice solving a problem by calling multiple functions, to practice passing data results be- tween functions Degree of Difficulty: Easy if you did everything right so far Now it's time to put all your functions together to print out a summary report of how many and what types of pokemon you can find on each continent. In the main part of your program, write code that will print to the console the name of each continent, the TOTAL number of different pokemon that can be found on that continent, followed by the counts for each For example, the format for your output might look something like this: Africa: 48 total pokemon 'ground': 3, 'fire': 1, 'fairy':1, 'ater': 9, 'g flying': 3, 'dragon' 1, electric': 2, 'grass': 2, 'normal': 4, poison':6, 'psychic': 3, 'rock': 4, 'bug': 3 t' 2, 'fighting': 4, South America: 55 total pokemon 'ground' 5, 'fire': 2, 'vater' 10, 'fighting': 2, 'flying': 4, dragon' 1, 'electric' 5, 'grass': 4, 'normal' 3, 'poison' 8, 'bug'6, 'rock' 2, 'psychic': 3 There will be more continents, but we're only showing two here to save space To do this, you will need to make use of all of the functions you have written so far and make good use of their inputs and outputs. If you've done everything correctly. this part of your program won't require a lot of code: just a few function calls and a single for-loop should be enough. rattata,normal,South America, Europe, Antarctica raticate, normal,0ceania 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 nidorina,poison,Africa, Europe,South America,Antarctica nidoqueen,poison,Africa,South America nidoranmale,poison,Asia,Africa,South America,North America nidorino,poison,Antarctica nidoking,poison,Africa, South America, Antarctica,Oceania clefairy,fairy,Asia clefable,fairy,Europe, North America vulpix, fire,North America,Antarctica,Oceania ninetales,fire, North America, Asia jigglypuff, fairy,Asia,Oceania, Europe,Africa wigglytuff,fairy,North America,Asia zubat,flying,Africa, Europe,Oceania,Asia golbat, flying,South America,Antarctica oddish, grass, Europe,Asia,North America gloom,grass,Oceania, Europe,Antarctica, North America vileplume, grass,Oceania,Antarctica paras,bug,Oceania,Antarctica,South America, Europe parasect,bug,Africa,South America,North America Overview Pokemon are fantastic creatures that people can catch and train. Pokemon are classified into different 'types such as grass, fire or electric. To catch different types of pokemon, you might have to travel all over the world! For this assignment, you will build a program that will help organize information about where to go to catch the different pokemon. This assignment is divided into 5 different questions', but in the end, your work from all of the questions will be combined to complete the overall program. The first four questions will each ask you to define a function that will perform a specific task. Make sure that the inputs (parameters) and outputs (return values) of your functions match the problem description exactly, or else the whole thing won't fit together properly! The following is a brief overview of how the questions for this assignment will fit together: Question 1 Read data about the pokemon from a text file and organize it as a database. You must fully complete this question before moving on. All of the other questions will depend on the database that you create here. Question 2: Build a list of all the unique co Question 3: Build a list of all the pokemon that can be found on a particular continent. Question 4: Count how many of each pokemon type occur within a given list of pokemon names. Question 5: For each continent, display the pokemon type counts. ntinents where you can find pokemon. Individually, none of these questions are particularly difficult, but if you make a mistake anywhere along the way, then the last part won't work. Make sure to perform simple testing, such as printing out lists or dictionaries. as you go to make sure that everything looks right. One last note of caution: we have given you an input file for this assignment, but be aware that we might test your program on a different input file. Therefore, you must make sure your code is fully general; don't count on knowing exactly how many pokemon there are, or on knowing exactly what the names of the pokemon types or locations might be Question 1 (6 points) Purpose: To practice the concept of dictionary as a database Degree of Difficulty: Moderate 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 11.19 of the text for a refresher on what databases look like using dictionaries. 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 grass1 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 i.e 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 pokemon's name, as a string The pokemon's type, as a string. . The locations where the pokemon can be found, as a list of strings. 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. Question 2 (4 points): Purpose: To practice iterating over nested Degree of Difficulty: Easy. Write a function called find_continents) which takes as parameter(s): A dictionary in the format of the pokemon database as described in O1 This function should construct and return a list of all the different continents where it is possible to find pokemon. Each entry in the list should be unique: in other words, don't add the same continent twice even if you can find multiple kinds of pokemon there. For the input file you were given, the resulting list should be (though not necessarily in this order: ['0ceania', 'Asia', 'South America', 'North America', 'Africa', Antarctica', 'Europe '] Also, note that this function must not change the pokemon database in any way. Question 3 (4 points): Purpose: To practice iterating over nested compound data and accessing different dictionary fields Degree of Diffculty: Easy Write a function called pokemon_in_continent ) which takes as parameterls): A dictionary in the format of the pokemon database as described in Q1 The name of a continent, as a string The function should construct and return a list containing the names of all of the pokemon that can be found on the given continent. For example, for the input file you were given, if the continent is "Africa" the resulting List should be (though not necessarily in this order) ['gyarados', 'nidorina''magmar', 'jigglypuff 'machoke', 'machamp', 'dragonair', 'slowbro ', 'machop'venomoth', 'tentacruel', 'parasect' omanyte''polivrath', 'muk', 'hitmonlee''vaporeon', 'tangela', 'gengar' nidoranmale', 'venusaur 'onix ','nidoking', 'golem', 'aerodactyl' tauros' 'metapod', 'electrode', 'lapras'psyduck','blastoise, 'nidoqueen' 'alakazam', 'cubone', 'magikarp 'kabutops', kakuna, oliwag', 'marowak' 'rhydon', 'kangaskhan', 'zubat', 'dodrio', 'persian', 'pikachu ', 'meouth', 'drouzee','gastly' Also, note that this function must not change the pokemon database in any way. Question 4 (4 points): Purpose: To practice summarizing data from a dictionary Degree of Difficulty: Moderate 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 Question 5 (5 points) Purpose: To practice solving a problem by calling multiple functions, to practice passing data results be- tween functions Degree of Difficulty: Easy if you did everything right so far Now it's time to put all your functions together to print out a summary report of how many and what types of pokemon you can find on each continent. In the main part of your program, write code that will print to the console the name of each continent, the TOTAL number of different pokemon that can be found on that continent, followed by the counts for each For example, the format for your output might look something like this: Africa: 48 total pokemon 'ground': 3, 'fire': 1, 'fairy':1, 'ater': 9, 'g flying': 3, 'dragon' 1, electric': 2, 'grass': 2, 'normal': 4, poison':6, 'psychic': 3, 'rock': 4, 'bug': 3 t' 2, 'fighting': 4, South America: 55 total pokemon 'ground' 5, 'fire': 2, 'vater' 10, 'fighting': 2, 'flying': 4, dragon' 1, 'electric' 5, 'grass': 4, 'normal' 3, 'poison' 8, 'bug'6, 'rock' 2, 'psychic': 3 There will be more continents, but we're only showing two here to save space To do this, you will need to make use of all of the functions you have written so far and make good use of their inputs and outputs. If you've done everything correctly. this part of your program won't require a lot of code: just a few function calls and a single for-loop should be enough. rattata,normal,South America, Europe, Antarctica raticate, normal,0ceania 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 nidorina,poison,Africa, Europe,South America,Antarctica nidoqueen,poison,Africa,South America nidoranmale,poison,Asia,Africa,South America,North America nidorino,poison,Antarctica nidoking,poison,Africa, South America, Antarctica,Oceania clefairy,fairy,Asia clefable,fairy,Europe, North America vulpix, fire,North America,Antarctica,Oceania ninetales,fire, North America, Asia jigglypuff, fairy,Asia,Oceania, Europe,Africa wigglytuff,fairy,North America,Asia zubat,flying,Africa, Europe,Oceania,Asia golbat, flying,South America,Antarctica oddish, grass, Europe,Asia,North America gloom,grass,Oceania, Europe,Antarctica, North America vileplume, grass,Oceania,Antarctica paras,bug,Oceania,Antarctica,South America, Europe parasect,bug,Africa,South America,North America
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
