Python代写 | CISC 106 Spring 2020 Project 1
CISC 106 Spring 2020 Project 1
March 31, 2020
For this project, you’ll be working with the PokeAPI ´ to build a simple Pokedex that can be ´
filtered based on the types of the Pokemon it contains. ´
After completing this project you will have gained the following Python programming experience:
• Using PyPi to locate/install third party packages.
• Writing a ”main” file, and seeing how to make Python load that in order to run your program.
• Using the requests library to:
– Make HTTP requests over the web.
– Extract the data returned in response to your request.
• Manipulating JSON data and transforming it into a format usable by the rest of your program.
• Designing and implementing simple Python classes.
• Hooking your code into other code you got from someone else.
2 Outline of Steps
The following section describes the steps you must take in order to complete this project.
Project Set Up
Prior to working on this project, you should install requests and pillow on your computer. See
installingmatplotlib.pdf on Canvas for instructions on how to install libraries in Thonny. Note
that the libary shown in these instructions is matplotlib, so you’ll rather want to follow those
instructions reaplacing ”matplotlib” everywhere you see it with ”requests”. Repeat this again for
pillow. You’ll be working with requests directly, and pillow is a dependency of the code I give you.
Download the following files from Canvas and put them in the same folder on your computer:
• show pokedex.py
Take a look at https://pokeapi.co/. If you scroll down on the page a bit, you should see a box
underneath ”Resource for ditto” that shows what the JSON data for a Pokemon looks like. If you ´
scroll to the bottom of the box and check ”View raw JSON”, that will let you see how the fancy
format the data is in by default maps back into regular JSON.
Take a look at the information contained in this JSON. Notably, you’ll want to see where
the Pokemon’s ´ species name is stored, as well as it’s 6 stats: hit points, attack, defense, special
attack, special defense and speed, it’s types, and it’s front default sprite are stored in this data.
Make a new file called pokemon.py in the same folder where you saved the files in the Project
Set Up step. You’ll write some code in this file, and then submit that to Canvas along with your
modified show pokedex.py
Open your pokemon.py file, and implement a Pokemon class. Your Pokemon should have the
• species – a string denoting the species name of the Pokemon ´
• hp – an integer representing the hit points stat of the Pokemon ´
• attack – an integer representing the attack stat of the Pokemon ´
• defense – an integer representing the defense stat of the Pokemon ´
• special attack – an integer representing the special attack stat of the Pokemon ´
• special defense – an integer representing the special defense stat of the Pokemon ´
• speed – an integer representing the speed stat of the Pokemon ´
• sprite – the raw data1
for the front default sprite of the Pokemon ´
• types – A list of string, each element being the name of a type. A Pokemon generally only ´
has one or two types, but you should write your code in such a way that it could have any
number of types.
Your Pokemon constructor should take in the JSON data you get from PokeAPI and set the ´
above attributes using that data.
Now implement a SimplePokedex class, also in pokemon.py. You can have whatever attributes
(with whatever types) you think you need for this class, but it should have the following interface
• The constructor should take in a list of instances of the Pokemon class you defined in Part
• The class should have a function all pokemon which simply returns a list of all Pokemon ´
in the Pokedex. ´
• The class should also have a function pokemon by type, which takes a string denoting a
type, and then returns a list of all the Pokemon in the Pok ´ edex of that type. ´
1Look at the documentation for requests for how to get this.
Open show pokemon.py. There is a lot of code in here! Luckily, you don’t need to grok most of
it to make the changes necessary to plug in your code. If you scroll down to toward the bottom,
you’ll see an if statement if name == ” main “:. In Python, this is typically seen in files
which are intended to be used as main entry points into a program. That is, these are files that
you run in order to launch an application. name == ” main ” will only be true in a particular
file if that file was run (as opposed to simply being imported by another file).
Look for the comment telling you how to hook in your Pokemon and SimplePokedex classes.
You should use requests to access the data for the original 150 Generation I Pokemon (that is, ´
Pokemon numbers ´ 1 thru 150. You can access a Pokemon by number as well as by name on ´
PokeAPI. See the ´ documentation for more information!), and create a SimplePokedex out of
When writing this code, try starting with the first 10, and then modify it to get all 150 once
you’ve got it working correctly. In this way, we hopefully won’t cause too much stress on
PokeAPI’s servers. ´
For an extra 1% on your final course grade, modify your pokemon by type function in your
SimplePokedex such that it can take in any number of types as input, and then returns a list
containing only the Pokemon whose type combination is those types passed in. ´ NB that the
interface of the function should not change in the case of only passing one type – that is, your
modified function should still work with show pokemon.py!
It’s preferable that you work in pairs for this project. Include the names of both partners at the
top of your pokemon.py and show pokemon.py files in a comment. You must both submit the
final files in Canvas.
Include a docstring for ALL functions created in this project.
3 Testing Your Code
Since there are a lot of you working on this project all at the same time, and we’d like to be good
neighbors to the folks at PokeAPI (who provide this API for free as a learning tool), please only ´
download the data for a few Pokemon and consider saving that data off to disk and loading it in ´
from there. For example, you can use this file containing the data for the original three Kanto
starters that I’ve made available on UD’s EECIS web server. This file is also available on Canvas.