Skip to content
Snippets Groups Projects
Commit 48b8afc6 authored by Ashwin Maran's avatar Ashwin Maran
Browse files

add lab-p4 and p4

parent be74ada0
No related branches found
No related tags found
No related merge requests found
Showing
with 9646 additions and 0 deletions
# Lab-P4: Conditional Statements and Pokémon API
In P4, you will be playing with some Pokémon and you will simulate simple Pokémon battles using conditional statements. In Lab-P4, you will learn to use `project.py`, which you will need to complete P4. You will also be introduced to some simple conditional statements and 'helper functions' which will be useful for P4.
### Corrections/Clarifications
None yet
**Find any issues?** Report to us:
- Ashwin Maran <amaran@wisc.edu>
------------------------------
## Learning Objectives
In this lab, you will practice...
* learning and using an 'API' (Application Programming Interface),
* building 'helper' functions that can be used to create more advanced functions,
* writing conditions using if/elif/else statements,
* writing advanced conditions using nested if/else statements,
* writing advanced conditions using logical operators (or/and).
------------------------------
## Note on Academic Misconduct
You may do these lab exercises only with your project partner; you are not allowed to start working on Lab-P4 with one person, then do the project with a different partner. Now may be a good time to review [our course policies](https://cs220.cs.wisc.edu/f23/syllabus.html).
------------------------------
## Project partner
We strongly recommend students find a project partner. Pair programming is a great way to learn from a fellow student. Project difficulty increases exponentially in this course. Finding a project partner early on during the semester is a good idea.
If you are still looking for a project partner, take a moment now to ask around the room if anyone would like to partner with you on this project. Then you can work with them on this lab as well as the project.
------------------------------
## Segment 1: Setup
Create a `lab-p4` directory and download the following files into the `lab-p4` directory:
* `pokemon_stats.csv`
* `type_effectiveness_stats.csv`
* `project.py`
* `lab-p4.ipynb`
* `public_tests.py`
**Note:** If you accidentally downloaded the file as a `.txt` (or `.cvs` or `.csv.txt`) instead of `.csv` (say `pokemon_stats.txt`), you can execute `mv pokemon_stats.txt pokemon_stats.csv` on a Terminal/PowerShell window. Recall that the `mv` (move) command lets you rename a source file (first argument in example: `pokemon_stats.txt`) to the destination file (second argument in example: `pokemon_stats.csv`).
Once you have downloaded the files, open a Terminal/PowerShell window and navigate to your `lab-p4` directory. Run `ls` to make sure the above files are available.
------------------------------
## Segment 2: Learning the API
You will be finishing the rest of your lab on `lab-p4.ipynb`. Run the command `jupyter notebook` from your Terminal/PowerShell window. Remember not to close this Terminal/PowerShell window while Jupyter is running, and open a new Terminal/PowerShell window if necessary.
**Note:** For P4, you will be working on `p4.ipynb` which is very similar to `lab-p4.ipynb`.
**Note:** Unlike `p4.ipynb`, you do **not** have to submit `lab-p4.ipynb`. This notebook is solely for your practice.
------------------------------
You can now get started with [P4](https://git.doit.wisc.edu/cdis/cs/courses/cs220/cs220-f23-projects/-/tree/main/p4). **You can copy/paste and use any helper function that you have created here in P4.** Good luck and have fun!
# Images
Images from lab-p4 are stored here.
lab-p4/images/add_new_cell.PNG

6.97 KiB

lab-p4/images/pokemon_stats.png

35.7 KiB

lab-p4/images/type_effectiveness_stats.png

28.8 KiB

This diff is collapsed.
This diff is collapsed.
__pokemon__= {}
__effectiveness__ = {}
def __init__():
"""This function loads the data from `pokemon_stats.csv` and `type_effectiveness_stats.csv`. This function runs automatically, when the module is imported"""
import csv
f = open('pokemon_stats.csv', encoding='utf-8')
raw_pkmn_data = list(csv.reader(f))
f.close()
pkmn_header = raw_pkmn_data[0]
pkmn_header.pop(0)
raw_pkmn_data = raw_pkmn_data[1:]
for pkmn_data in raw_pkmn_data:
pkmn_data.pop(0)
pkmn = {}
for i in range(len(pkmn_header)):
pkmn[pkmn_header[i]] = pkmn_data[i]
for stat in pkmn:
if stat in ['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed']:
pkmn[stat] = int(pkmn[stat])
__pokemon__[pkmn["Name"]] = pkmn
f = open('type_effectiveness_stats.csv', encoding='utf-8')
raw_type_data = list(csv.reader(f))
f.close()
type_header = raw_type_data[0]
raw_type_data = raw_type_data[1:]
for type1 in type_header[1:]:
__effectiveness__[type1] = {}
for row in raw_type_data:
type2 = row[0]
for i in range(1, len(row)):
type1 = type_header[i]
__effectiveness__[type1][type2] = float(row[i])
def print_stats(pkmn):
"""print_stats(pkmn) prints all the statistics of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
for stat in __pokemon__[pkmn]:
if not (stat == 'Type 2' and __pokemon__[pkmn][stat] == "DNE"):
print(stat, ": ", __pokemon__[pkmn][stat])
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_region(pkmn):
"""get_region(pkmn) returns the region of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Region']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_type1(pkmn):
"""get_type1(pkmn) returns Type 1 of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Type 1']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_type2(pkmn):
"""get_type2(pkmn) returns Type 2 of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Type 2']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_hp(pkmn):
"""get_hp(pkmn) returns the HP of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['HP']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_attack(pkmn):
"""get_attack(pkmn) returns the Attack of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Attack']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_defense(pkmn):
"""get_defense(pkmn) returns the Defense of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Defense']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_sp_atk(pkmn):
"""get_sp_atk(pkmn) returns the Special Attack of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Sp. Atk']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_sp_def(pkmn):
"""get_sp_def(pkmn) returns the Special Defense of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Sp. Def']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_speed(pkmn):
"""get_speed(pkmn) returns the Speed of the Pokémon with the name `pkmn`"""
if pkmn in __pokemon__:
return __pokemon__[pkmn]['Speed']
else:
raise Exception("Pokémon '" + pkmn + "' not found in the file")
def get_type_effectiveness(attacker_type, defender_type):
"""get_type_effectiveness(attacker_type, defender_type) returns the effectiveness of `attacker_type` attacks against `defender_type` Pokémon"""
if attacker_type in __effectiveness__ and defender_type in __effectiveness__[attacker_type]:
return __effectiveness__[attacker_type][defender_type]
elif attacker_type not in __effectiveness__:
if defender_type not in __effectiveness__:
raise Exception("Type '" + attacker_type + "' and Type '" + defender_type + "' not found in the file")
else:
raise Exception("Type '" + attacker_type + "' not found in the file")
else:
raise Exception("Type '" + defender_type + "' not found in the file")
__init__()
This diff is collapsed.
,Normal,Fire,Water,Electric,Grass,Ice,Fighting,Poison,Ground,Flying,Psychic,Bug,Rock,Ghost,Dragon,Dark,Steel,Fairy
Normal,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0
Fire,1.0,0.5,2.0,1.0,0.5,0.5,1.0,1.0,2.0,1.0,1.0,0.5,2.0,1.0,1.0,1.0,0.5,0.5
Water,1.0,0.5,0.5,2.0,2.0,0.5,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.5,1.0
Electric,1.0,1.0,1.0,0.5,1.0,1.0,1.0,1.0,2.0,0.5,1.0,1.0,1.0,1.0,1.0,1.0,0.5,1.0
Grass,1.0,2.0,0.5,0.5,0.5,2.0,1.0,2.0,0.5,2.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0
Ice,1.0,2.0,1.0,1.0,1.0,0.5,2.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,2.0,1.0
Fighting,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.0,2.0,0.5,0.5,1.0,1.0,0.5,1.0,2.0
Poison,1.0,1.0,1.0,1.0,0.5,1.0,0.5,0.5,2.0,1.0,2.0,0.5,1.0,1.0,1.0,1.0,1.0,0.5
Ground,1.0,1.0,2.0,0.0,2.0,2.0,1.0,0.5,1.0,1.0,1.0,1.0,0.5,1.0,1.0,1.0,1.0,1.0
Flying,1.0,1.0,1.0,2.0,0.5,2.0,0.5,1.0,0.0,1.0,1.0,0.5,2.0,1.0,1.0,1.0,1.0,1.0
Psychic,1.0,1.0,1.0,1.0,1.0,1.0,0.5,1.0,1.0,1.0,0.5,2.0,1.0,2.0,1.0,2.0,1.0,1.0
Bug,1.0,2.0,1.0,1.0,0.5,1.0,0.5,1.0,0.5,2.0,1.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0
Rock,0.5,0.5,2.0,1.0,2.0,1.0,2.0,0.5,2.0,0.5,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0
Ghost,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.5,1.0,1.0,1.0,0.5,1.0,2.0,1.0,2.0,1.0,1.0
Dragon,1.0,0.5,0.5,0.5,0.5,2.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,2.0
Dark,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,0.0,2.0,1.0,0.5,1.0,0.5,1.0,2.0
Steel,0.5,2.0,1.0,1.0,0.5,0.5,2.0,0.0,2.0,0.5,0.5,0.5,0.5,1.0,0.5,1.0,0.5,0.5
Fairy,1.0,1.0,1.0,1.0,1.0,1.0,0.5,2.0,1.0,1.0,1.0,0.5,1.0,1.0,0.0,0.5,2.0,1.0
# Project 4 (P4): Pokémon Battle Simulation
## Clarifications/Corrections:
* None yet.
**Find any issues?** Report to us:
- John Balis <balis@wisc.edu>
- Tunan Wang <tunan.wang@wisc.edu>
## Note on Academic Misconduct:
You are **allowed** to work with a partner on your projects. While it is not required that you work with a partner, it is **recommended** that you find a project partner as soon as possible as the projects will get progressively harder. Be careful **not** to work with more than one partner. If you worked with a partner on Lab-P4, you are **not** allowed to finish your project with a different partner. You may either continue to work with the same partner, or work on P4 alone. Now may be a good time to review our [course policies](https://cs220.cs.wisc.edu/f23/syllabus.html).
## Instructions:
In this project, we will focus on conditional statements. To start, create a `p4` directory, and download `p4.ipynb`, `project.py`, `public_tests.py`, `pokemon_stats.csv`, and `type_effectiveness_stats.csv`.
**Note:** Please go through [Lab-P4](https://git.doit.wisc.edu/cdis/cs/courses/cs220/cs220-f23-projects/-/tree/main/lab-p4) before you start the project. The lab contains some very important information that will be necessary for you to finish the project.
You will work on `p4.ipynb` and hand it in. You should follow the provided directions for each question. Questions have **specific** directions on what **to do** and what **not to do**.
After you've downloaded the file to your `p4` directory, open a terminal window and use `cd` to navigate to that directory. To make sure you're in the correct directory in the terminal, type `pwd`. To make sure you've downloaded the notebook file, type `ls` to ensure that `p4.ipynb`, `project.py`, `public_tests.py`, `pokemon_stats.csv`, and `type_effectiveness_stats.csv` are listed. Then run the command `jupyter notebook` to start Jupyter, and get started on the project!
**IMPORTANT**: You should **NOT** terminate/close the session where you run the above command. If you need to use any other Terminal/PowerShell commands, open a new window instead. Keep constantly saving your notebook file, by either clicking the "Save and Checkpoint" button (floppy disk) or using the appropriate keyboard shortcut.
------------------------------
## IMPORTANT Submission instructions:
- Review the [Grading Rubric](https://git.doit.wisc.edu/cdis/cs/courses/cs220/cs220-f23-projects/-/tree/main/p4/rubric.md), to ensure that you don't lose points during code review.
- Login to [Gradescope](https://www.gradescope.com/) and upload the zip file into the P4 assignment.
- If you completed the project with a **partner**, make sure to **add their name** by clicking "Add Group Member"
in Gradescope when uploading the P4 zip file.
<img src="images/add_group_member.png" width="400">
**Warning:** You will have to add your partner on Gradescope even if you have filled out this information in your `p4.ipynb` notebook.
- It is **your responsibility** to make sure that your project clears auto-grader tests on the Gradescope test system. Otter test results should be available within forty minutes after your submission (usually within ten minutes). **Ignore** the `-/100.00` that is displayed to the right. You should be able to see both PASS / FAIL results for the 20 test cases, which is accessible via Gradescope Dashboard (as in the image below):
<img src="images/gradescope.png" width="400">
- You can view your **final score** at the **end of the page**. If you pass all tests, then you will receive **full points** for the project. Otherwise, you can see your final score in the **summary** section of the test results (as in the image below):
<img src="images/summary.png" width="400">
If you want more details on why you lost points on a particular test, you can scroll up to find more details about the test.
%% Cell type:code id: tags:
``` python
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
```
%% Cell type:code id: tags:
``` python
dex_url = "https://pokemondb.net/pokedex/all"
re = requests.get(dex_url)
re.raise_for_status()
raw_dex_data = bs(re.text, 'html.parser')
pokemon = []
pokemon_order = {}
tables = raw_dex_data.find_all('a', attrs={'class':'ent-name'})
count = 0
for link in tables:
if link.text not in pokemon:
pokemon.append(link.text)
pokemon_order[link.text] = count
count+=1
```
%% Cell type:code id: tags:
``` python
pokemon_url = {}
for pkmn in pokemon:
pokemon_url[pkmn] = ('https://pokemondb.net/pokedex/' + pkmn)
pokemon_url['Pikachu']
```
%% Output
'https://pokemondb.net/pokedex/Pikachu'
%% Cell type:code id: tags:
``` python
# this cell takes a very long time, it scrapes every pokedex entry
raw_pokemon_data = {}
for pkmn in pokemon_url:
try:
re = requests.get(pokemon_url[pkmn])
re.raise_for_status()
raw_pokemon_data[pkmn] = (bs(re.text, 'html.parser'))
except:
pass
len(raw_pokemon_data)
```
%% Output
981
%% Cell type:code id: tags:
``` python
raw_pokemon_stats = {}
headers = ['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed']
for pkmn in raw_pokemon_data:
raw_pokemon_tables = raw_pokemon_data[pkmn].find_all('table')
for table in raw_pokemon_tables:
correct_table = True
table_headers = [header.get_text() for header in table.find_all('th')]
for header in headers:
if header not in table_headers:
correct_table = False
if correct_table and pkmn not in raw_pokemon_stats:
raw_pokemon_stats[pkmn] = table
raw_pokemon_stats['Pikachu']
```
%% Output
<table class="vitals-table">
<tbody>
<tr>
<th>HP</th>
<td class="cell-num">35</td>
<td class="cell-barchart">
<div class="barchart-bar barchart-rank-2" style="width:19.44%;"></div>
</td>
<td class="cell-num">180</td>
<td class="cell-num">274</td>
</tr>
<tr>
<th>Attack</th>
<td class="cell-num">55</td>
<td class="cell-barchart">
<div class="barchart-bar barchart-rank-2" style="width:30.56%;"></div>
</td>
<td class="cell-num">103</td>
<td class="cell-num">229</td>
</tr>
<tr>
<th>Defense</th>
<td class="cell-num">40</td>
<td class="cell-barchart">
<div class="barchart-bar barchart-rank-2" style="width:22.22%;"></div>
</td>
<td class="cell-num">76</td>
<td class="cell-num">196</td>
</tr>
<tr>
<th>Sp. Atk</th>
<td class="cell-num">50</td>
<td class="cell-barchart">
<div class="barchart-bar barchart-rank-2" style="width:27.78%;"></div>
</td>
<td class="cell-num">94</td>
<td class="cell-num">218</td>
</tr>
<tr>
<th>Sp. Def</th>
<td class="cell-num">50</td>
<td class="cell-barchart">
<div class="barchart-bar barchart-rank-2" style="width:27.78%;"></div>
</td>
<td class="cell-num">94</td>
<td class="cell-num">218</td>
</tr>
<tr>
<th>Speed</th>
<td class="cell-num">90</td>
<td class="cell-barchart">
<div class="barchart-bar barchart-rank-4" style="width:50.00%;"></div>
</td>
<td class="cell-num">166</td>
<td class="cell-num">306</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Total</th>
<td class="cell-num cell-total">320</td>
<th class="cell-barchart"></th>
<th>Min</th>
<th>Max</th>
</tr>
</tfoot>
</table>
%% Cell type:code id: tags:
``` python
regions = {1: "Kanto", 2: "Johto", 3: "Hoenn", 4: "Sinnoh", 5: "Unova", 6: "Kalos", 7: "Alola", 8: "Galar", 9: "Paldea"}
pokemon_stats = []
for pkmn in raw_pokemon_stats:
stats = {}
raw_stats = raw_pokemon_stats[pkmn].find_all('tr')
stats['Name'] = pkmn
generation_text = raw_pokemon_data[pkmn].find('p').text
generation_idx = generation_text.find('Generation')
generation = int(generation_text[generation_idx + len('Generation ')])
stats["Region"] = regions[generation]
pkmn_types = raw_pokemon_data[pkmn].find('table').find_all('td')[1].find_all('a')
stats['Type 1'] = pkmn_types[0].text
if len(pkmn_types) > 1:
stats['Type 2'] = pkmn_types[1].text
else:
stats['Type 2'] = 'DNE'
for stat in raw_stats:
stat_name = stat.find('th').get_text()
stat_num = stat.find('td').get_text()
if stat_name in headers:
stats[stat_name] = stat_num
pokemon_stats.append(stats)
pokemon_stats = sorted(pokemon_stats, key = lambda x: pokemon_order[x['Name']])
pokemon_stats[:3]
```
%% Output
[{'Name': 'Bulbasaur',
'Region': 'Kanto',
'Type 1': 'Grass',
'Type 2': 'Poison',
'HP': '45',
'Attack': '49',
'Defense': '49',
'Sp. Atk': '65',
'Sp. Def': '65',
'Speed': '45'},
{'Name': 'Ivysaur',
'Region': 'Kanto',
'Type 1': 'Grass',
'Type 2': 'Poison',
'HP': '60',
'Attack': '62',
'Defense': '63',
'Sp. Atk': '80',
'Sp. Def': '80',
'Speed': '60'},
{'Name': 'Venusaur',
'Region': 'Kanto',
'Type 1': 'Grass',
'Type 2': 'Poison',
'HP': '80',
'Attack': '82',
'Defense': '83',
'Sp. Atk': '100',
'Sp. Def': '100',
'Speed': '80'}]
%% Cell type:code id: tags:
``` python
cols = ["Name","Attack","Defense","HP","Region","Sp. Atk","Sp. Def","Speed","Type 1","Type 2"]
df = pd.DataFrame(pokemon_stats)
df = df[cols]
df.to_csv('pokemon_stats.csv')
```
%% Cell type:code id: tags:
``` python
type_url = "https://pokemondb.net/type"
re = requests.get(type_url)
re.raise_for_status()
raw_type_data = bs(re.text, 'html.parser')
effectiveness = {}
raw_to_numbers = {'normal': 1.0, 'not': 0.5, 'super-effective': 2.0, 'no': 0.0}
table = raw_type_data.find('table')
rows = table.find_all('tr')[1:]
for row in rows:
cells = row.find_all('td')
for cell in cells:
data = cell.attrs['title']
types, val = data.split(' = ')
type1, type2 = types.split("")
val = val.split()[0]
if type1 not in effectiveness:
effectiveness[type1] = {}
effectiveness[type1][type2] = raw_to_numbers[val]
effectiveness['Fire']
```
%% Output
{'Normal': 1.0,
'Fire': 0.5,
'Water': 0.5,
'Electric': 1.0,
'Grass': 2.0,
'Ice': 2.0,
'Fighting': 1.0,
'Poison': 1.0,
'Ground': 1.0,
'Flying': 1.0,
'Psychic': 1.0,
'Bug': 2.0,
'Rock': 0.5,
'Ghost': 1.0,
'Dragon': 0.5,
'Dark': 1.0,
'Steel': 2.0,
'Fairy': 1.0}
%% Cell type:code id: tags:
``` python
df = pd.DataFrame(effectiveness)
df.to_csv('type_effectiveness_stats.csv')
```
# Images
Images from p4 are stored here.
p4/images/add_group_member.png

157 KiB

p4/images/gradescope.png

60.5 KiB

p4/images/pokemon.jpg

371 KiB

p4/images/summary.png

20.1 KiB

p4/p4.ipynb 0 → 100644
This diff is collapsed.
This diff is collapsed.
__pokemon__= {}
__effectiveness__ = {}
def __init__():
"""This function loads the data from 'pokemon_stats.csv' and 'type_effectiveness_stats.csv'. This function runs automatically, when the module is imported"""
import csv
f = open('pokemon_stats.csv', encoding='utf-8')
raw_pkmn_data = list(csv.reader(f))
f.close()
pkmn_header = raw_pkmn_data[0]
pkmn_header.pop(0)
raw_pkmn_data = raw_pkmn_data[1:]
for pkmn_data in raw_pkmn_data:
pkmn_data.pop(0)
pkmn = {}
for i in range(len(pkmn_header)):
pkmn[pkmn_header[i]] = pkmn_data[i]
for stat in pkmn:
if stat in ['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed']:
pkmn[stat] = int(pkmn[stat])
__pokemon__[pkmn["Name"]] = pkmn
f = open('type_effectiveness_stats.csv', encoding='utf-8')
raw_type_data = list(csv.reader(f))
f.close()
type_header = raw_type_data[0]
raw_type_data = raw_type_data[1:]
for type1 in type_header[1:]:
__effectiveness__[type1] = {}
for row in raw_type_data:
type2 = row[0]
for i in range(1, len(row)):
type1 = type_header[i]
__effectiveness__[type1][type2] = float(row[i])
def print_stats(pkmn):
"""print_stats(pkmn) prints all the statistics of the Pokémon with the name 'pkmn' """
try:
for stat in __pokemon__[pkmn]:
if not (stat == 'Type 2' and __pokemon__[pkmn][stat] == "DNE"):
print(stat, ": ", __pokemon__[pkmn][stat])
except KeyError:
print(pkmn, " not found in the file")
def get_region(pkmn):
"""get_region(pkmn) returns the region of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Region']
def get_type1(pkmn):
"""get_type1(pkmn) returns Type 1 of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Type 1']
def get_type2(pkmn):
"""get_type2(pkmn) returns Type 2 of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Type 2']
def get_hp(pkmn):
"""get_hp(pkmn) returns the HP of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['HP']
def get_attack(pkmn):
"""get_attack(pkmn) returns the Attack of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Attack']
def get_defense(pkmn):
"""get_defense(pkmn) returns the Defense of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Defense']
def get_sp_atk(pkmn):
"""get_sp_atk(pkmn) returns the Special Attack of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Sp. Atk']
def get_sp_def(pkmn):
"""get_sp_def(pkmn) returns the Special Defense of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Sp. Def']
def get_speed(pkmn):
"""get_speed(pkmn) returns the Speed of the Pokémon with the name 'pkmn' """
return __pokemon__[pkmn]['Speed']
def get_type_effectiveness(attacker_type, defender_type):
"""get_type_effectiveness(attacker_type, defender_type) returns the effectiveness of attacker's type against defender's type"""
return __effectiveness__[attacker_type][defender_type]
__init__()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment