Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What\'s allowed? Here is the exhaustive list of things you can use on the projec

ID: 3823620 • Letter: W

Question

What's allowed?

Here is the exhaustive list of things you can use on the project. You can ask if we've omitted something, but the answer is probably no. • all basic expressions/operators, indexing/slicing. • all basic statements: assignment, selection, and loop statements, break/continue, return • functions: len(), range(), int(), float(), str(), set(), dict(), bool(), tuple() • file reading: open(), .close(), .read(), .readline(), .readlines(), with syntax • dictionaries: all methods listed in our slides on that chart • methods: lists: .insert(), .append(), .extend(), .pop(), .remove() strings: .strip(), .split(), .join() • sorted(), .sort(), reversed(), .reverse()

This means that… • you can't call anything not listed above. Focus on applying these functions to solve the task • you can't import any modules for this project (e.g. you can't import csv) • you can’t use try-except for this assignment 2

Procedure Complete the function definitions as described; you can test your code with the included testing file. • Sample csv files have been provided with this assignment • You can look for example file contents & databases, starting around line 75 or so in the tester. • Invoke it as with prior assignments: python3 tester5p.py yourcode.py • You can also test individual functions: python3 tester5p.py yourcode.py get_types • You can also run your code in interactive mode: python3 –i yourcode.py • Note that there are 64 test cases worth1.25 points each, and 5 extra credit tests worth 1 point each.

Scenario The Pokemon franchise consists of over 60 video games, 15 movies, several TV shows, a trading card game, and even a musical. It has been around for over two decades and at this point has fans of all ages. Because of this, people have become somewhat analytical about how they play the games. To help players of the Pokemon video games, some people have created a Pokemon data set with all the useful statistics, while other people have created data sets with the Pokemon’s other properties (such as type). 1 It will be your job to merge together these two data sets and give players some useful statistics and analysis of what you find.

CSV file: This is a file containing ASCII text where each line in the file represents one record of information, and each piece of info in the record is separated by a single comma. The very first line is the "header" row, which names the columns but is not part of the data. You will be given two CSV files to work with: an “info” file (containing information such as the Pokemon’s “type” and the “generation” of the game it was introduced in) as well as a “stats” file (containing information on how good the Pokemon is at various things, such as “attack” and “defense”).

Below are two very small sample files that can be used in our project. Note: the file extension has no effect on the file contents; you can edit these files in your code editor, and you can give them any extension you want without changing the ability of your program. It's best not to use MS Excel, as it often uses several different notions of what a CSV file should be and it is easy to mess them up.

Example “info” file: "ID","Name","Type 1","Type 2","Generation","Legendary" 1,"Bulbasaur","Grass","Poison",1,"FALSE"

6,"Charizard","Fire","Flying",1,"FALSE"

4,"Charmander","Fire","",1,"FALSE"

169,"Crobat","Poison","Flying",2,"FALSE"

146,"Moltres","Fire","Flying",1,"TRUE" 643,"Reshiram","Dragon","Fire",5,"TRUE"

641,"Tornadus, (Incarnate Form)","Flying","",5,"TRUE"

Example “stats” file: "ID","HP","Attack","Defense","Speed"

1,45,49,49,45

4,39,52,43,65

6,78,84,78,100

146,90,100,90,90

149,91,134,95,80

641,79,115,70,111

643,100,120,100,90 1

These data sets actually come from a single data set available for free here: https://www.kaggle.com/abcsds/pokemon.

Pokemon: We will use three different representations for a Pokemon inside our programs, but all three will be based on a tuple with values in some order. The first format (based on the information in an “info” file) will be called INFO FORMAT and will consist of a key-value pair structured as the following examples.

# name: (id, type1, type2, generation, legendary)

# 'Bulbasaur': (1, 'Grass', 'Poison', 1, False)

# 'Charmander': (4, 'Fire', None, 1, False)

The second format (based on the information in a “stats” file) will be called STATS FORMAT and will consist of a key-value pair structured as follows:

# id: (hp, attack, defense, speed)

# 1: (45, 49, 49, 45)

The final format for a Pokemon will combine the two prior formats into a format for our DATABASE (see next section) and will consist of a key-value pair with the following structure:

# name: (id, type1, type2, hp, attack, defense, speed, generation, legendary)

# 'Bulbasaur': (1, 'Grass', 'Poison', 45, 49, 49, 45, 1, False)

Note that name, type1, and type2 fields are strings, id, generation, and all the stats are integers, and the Pokemon’s legendary status is a boolean. Additionally, for pokemon that aren’t dual type, the 2nd type is set to be None. (Also notice that none of the formats duplicate the key as part of the data, as duplicated information is rarely a good idea).

Database: a "database" of Pokemon can store multiple Pokemon by name. Our database will be a dictionary whose keys are Pokemon names, and whose values are tuples of interesting information about the Pokemon (in the combined final database format shown above). Only Pokemon with stored information and statistics may be present.

sample_db = {

"Bulbasaur": (1, "Grass", "Poison", 45, 49, 49, 45, 1, False),

"Charmander": (4, "Fire", None, 39, 52, 43, 65, 1, False),

"Charizard": (6, "Fire", "Flying", 78, 84, 78,100, 1, False),

"Moltres": (146, "Fire", "Flying", 90,100, 90, 90, 1, True),

"Crobat": (169, "Poison", "Flying", 85, 90, 80,130, 2, False),

"Tornadus, (Incarnate Form)": (641, "Flying", None, 79,115, 70,111, 5, True),

"Reshiram": (643, "Dragon", "Fire", 100,120,100, 90, 5, True) }

Functions You must implement the following functions. Examples can be found later in this document (under “Examples”). Methods NEVER modify the given database; but some functions create a new database.

pokemon_by_types(db, types): This function accepts a pokemon database db and a list of strings types. It needs to build and return a new database with only pokemon of the given types. NOTE: you must not change the original database with this function.

pokemon_by_hp_defense(db, lowest_hp, lowest_defense): Given a pokemon database db and two integers indicating the lowest hit points (hp) and lowest defense stats, this function creates and returns a new database consisting only of pokemon with an hp >= lowest_hp and a defense >= lowest_defense. NOTE: you must not change the original database with this function.

get_types(db): Given a database db, this function determines all the pokemon types in the database. It returns the types as a list of strings, asciibatically sorted (in order based on the ASCII character values). The sorted() function or .sort() method can be helpful here.

count_by_type(db,type): Given a database db and a single pokemon type (as a string), this function collects and reports three statistics: 1.how many pokemon in db have type as their only type 2.how many dual-type pokemon in db have type as one of their two types 3.a sum of the two values (1 and 2) above A tuple of (single_type_count, dual_type_count, total_count) should be returned.

fastest_type(db): Given a database db, determine the type with the highest average speed. Ties are possible, so return a list of types (strings) sorted asciibatically. Hints: The sorted() function or .sort() method can be helpful here, as can get_types() and pokemon_by_types().

legendary_count_of_types(db): Given a database db, for every type in that database, count how many pokemon of that type are legendary. Create a new dictionary to report the counts. It should have one entry for every type in the original database and be structured in the format: type: count_of_legendary. For example, { "Fire": 2, "Ground": 1 }. Hint: get_types() and pokemon_by_types() could be helpful here.

team_hp(db, team): Given a database db and a list of pokemon names (as strings) team, find out the total hps of all pokemon on that team and return it as an integer. Assume all pokemon on the team are included in the database.

show_of_strength_game(db, team1, team2): Given a database db and two teams (two separate lists of pokemon names), have the teams play out a competition where each pokemon competes against the corresponding pokemon on the other team. Assume all pokemon are listed in the database. A team will “win” a match if the pokemon on their team has a higher “attack” stat. If only one team has a pokemon to compete in that slot, that team wins automatically. Return the difference between Team1’s score and Team2’s score. For example:

Team1 = ["Pokemon1", "Pokemon2", "Pokemon3", "Pokemon4"]

Team1 = ["Pokemon5", "Pokemon6"]

[Team1] [Team2]

Pokemon1 Pokemon5 # Pokemon5 has higher attack than Pokemon1, therefore Team2 wins

Pokemon2 Pokemon6 # Pokemon2 has higher attack than Pokemon6, therefore Team1 wins

Pokemon3 # Team2 ran out of pokemon, so Team1 automatically wins

Pokemon4 # Team2 ran out of pokemon, so Team1 automatically wins

Team1 wins three times, Team2 wins one time, return 3-1 = 2.

strongest_pokemon(db, type = None, generation = None): Given a database of pokemon db, determine the pokemon with the highest total of hp, attack, and defense. If the user decides to restrict the type or generation, provide only the strongest pokemon that also meet those criteria. Since ties are possible, return a list of the strongest pokemon by name, asciibatically sorted. Return None if no pokemon meet the specified requirements. Hint: The sorted() function or .sort() method can be helpful here.

Explanation / Answer

output:

stats_db: {1: (45, 49, 49, 45), 146: (90, 100, 90, 90), 643: (100, 120, 100, 90), 4: (39, 52, 43, 65), 149: (91, 134, 95, 80), 6: (78, 84, 78, 100), 641: (79, 115, 70, 111)}
info_db: {1: ('Bulbasaur', 'Grass', 'Posison', 1, False), 146: ('Moltres', 'Fire', 'Flying', 1, True), 643: ('Reshiram', 'Dragon', 'Fire', 5, True), 4: ('Charmander', 'Fire', None, 1, False), 6: ('Charizard', 'Fire', 'Flying', 1, False), 641: ('Tornadus (Incarnate Form)', 'Flying', None, 1, True), 169: ('Crobat', 'Posison', 'Flying', 2, False)}
DB: {'Charmander': (4, 'Fire', None, 39, 52, 43, 65, 1, False), 'Charizard': (6, 'Fire', 'Flying', 78, 84, 78, 100, 1, False), 'Bulbasaur': (1, 'Grass', 'Posison', 45, 49, 49, 45, 1, False), 'Moltres': (146, 'Fire', 'Flying', 90, 100, 90, 90, 1, True), 'Tornadus (Incarnate Form)': (641, 'Flying', None, 79, 115, 70, 111, 1, True), 'Reshiram': (643, 'Dragon', 'Fire', 100, 120, 100, 90, 5, True)}
pokemon_by_types {'Reshiram': (643, 'Dragon', 'Fire', 100, 120, 100, 90, 5, True)}
pokemon_by_hp_defense {'Reshiram': (643, 'Dragon', 'Fire', 100, 120, 100, 90, 5, True), 'Moltres': (146, 'Fire', 'Flying', 90, 100, 90, 90, 1, True)}
Pokemon Type: ['Dragon', 'Fire', 'Flying', 'Grass', 'Posison']
['Flying']
{'Fire': 2, 'Flying': 2, 'Dragon': 1}

Process finished with exit code 0

note :

all other things are compleed

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote