Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have posted everything that my prof gave me. ( and I only struggle with question 4 and 5) bulbasaur, grass, South America Ivysaur, grass,
I have posted everything that my prof gave me. ( and I only struggle with question 4 and 5)
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 Aerica 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 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 elefairy, 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 qolbat, 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 venonat, poison, North America, South America venomoth. poison, Africa, Europe, Antarctica diglett.ground, Europe, South America, Asia, Oceania dugtrio,ground, North America, Europe, South America meowth, normal, Africa persian, normal, North America, Oceania, Africa, Antarctica psyduck, water, Africa, North America golduck, water, Antarctica, South America, Europe, Asia mankey, fighting, North America, Oceania, South America primeape, fighting, Oceania growlithe, fire, Antarctica, North America areanine, fire, Europe poliwag, water, Europe, Africa, Antarctica, Oceania poliwhirl, water, Europe poliwrath, water, Africa, Antarctica, Asia abra, psychie, North America kadabra, psychic, Oceania, Europe, Antarctica, South America alakazam, psychic, Africa machop, fighting, Africa machoke, fighting, North America, South America, Antarctica, Africa machamp, fighting, Asia, North America, Oceania, Africa bellsprout, grass, Antarctica, North America weepinbell, grass, Asia, South America victreebel, grass, South 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 pokemon types. Question 3. Build a list of all the pokemon names that belong to a particular type. Question 4: Count how many times each continent occurs within a given list of pokemon names Question 5: For each pokemon type, display the continent counts. Also, make a bar chart to display the count of each pokemon type. 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 hle. Therefore, you must make sure your code is fully general: dont count on knowing exactly how many pokemon names/types there are, or on knowing exactly what locations there might be What to Hand In When you're done, you'll hand in one document, a5.py, with ALL your work in it. Make sure you put identifica- tion information (name, NSID, student number and instructor's name) at the top of your program! 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 pokemonTypes.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 type data file This function should return a database (ie, 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 grass. 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 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 1 Yes, we are aware that in fact Pokemon can have more than one type. Question 2 (4 points): Purpose: To practice iterating over data Degree of Difficulty: Easy. Write a function called find_types() which takes as parameter(s) A dictionary in the format of the pokemon database as described in Q1 This function should construct and return a list of all the different pokemon types. Each entry in the list should be unique in other words, don't add the same pokemon type twice. For the input file you were given the resulting list should be (though not necessarily in this order): ['water', 'bug', 'dragon', 'fire', 'fairy', 'flying', grass', 'poison', 'ground', 'psychic', 'normal', 'electric', 'rock', 'ghost', 'fighting', 'ice'] 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 Difficulty: Easy. Write a function called type_names() which takes as parameter(s) A dictionary in the format of the pokemon database as described in 01 The name of a type, as a string The function should construct and return a list containing the pokemon names that belong to a particular pokemon type. For example, for the input file you were given if the type is "electric", the resulting list should be (though not necessarily in this order): ['pikachu', magneton', 'raichu', 'voltorb', 'electrode', zapdos', 'magnemite', 'jolteon', 'electabuzz'] 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_locations() which takes as parameter(s): A dictionary in the format of the pokemon database as described in 01 A list of pokemon names (as strings) This function should construct and return a dictionary where each key is a location (eg. North America or Asia, etc...) and the value for that key is the number of pokemon names found in that location in the given list. Recall locations' as one of the fields for each pokemon record in the database. For example, using the sample list of all of the pokemon names from "electric type (see Q3 to see that list), the resulting dictionary should be (though not necessarily in this order): {'Asia': 3, 'Africa': 2, 'Antarctica': 2, 'Oceania': 3, North America': 4, South America': 5, 'Europe': 5} Also, note that this function must not change the pokemon database or the given list of pokemon names in any way. Question 5 (7 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 display a summary report of the numer of pokemon of each type that are found on specific continents, and a bar chart to your computer's screen. (a) In the main program, write code that will print to the console the name of each pokemon type, the TOTAL number of different pokemon names belonging to that type, followed by the counts for number of pokemon found in each location for that specific type. For example, the format for your output might look something like this: 'electric' type contains 9 pokemon. Below are the locations, where pokemon of type 'electric' can be caught and the number of pokemon of that specific type found on those locations. { 'North America': 4, 'Asia': 3, 'Antarctica': 2, 'Africa': 2, 'Oceania': 3, 'Europe': 5, South America': 5} 'fire' type contains 12 pokemon. Below are the locations, where pokemon of type 'fire' can be be caught and the number of pokemon of that specific type found on those locations. {'North America': 4, 'Asia': 1, 'Antarctica': 5, 'Africa': 1, Oceania': 4, "South America': 2, 'Europe': 4} There will be more types, but we're only showing two here to save space (b) For the second part, write code that will make a bar chart showing the count of each pokemon type The resulting chart might look like as follows: Total number of pokemon of different types Number of pokemon III...lol.illi fighting bug rock poison dragon hoste normal ground Tying for psychic grass water tre electric Pokemon Types Fortunately, this is relatively easy to draw, if you have a list or dictionary that contains a count of each pokemon type. One way you can do this is make a dictionary typetonamecount where keys are poke- mon types and values are the number of pokemon that belong to that type. You can make use of the same loop from first part of the main program. There's a method in matplotlib.pyplot called bar() to draw bar chart of categorical data, and it takes a range of values, list, color etc, as arguments. The labels for x are then provided by a method in matplotlib.pyplot called xticks(). which takes range along X-axis, a list of categorial variables, size etc. as arguments. Give your chart a meaningful title and labels for x and y axes! You may wish to adjust the style by using the ggplot style. Don't forget to call show(). To write solution to this question, 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 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