Question
Python!! Help please ASAP there are examples given, but I have some errors with the codes I originally have. I have the following code that
Python!! Help please ASAP there are examples given, but I have some errors with the codes I originally have.
I have the following code that have errors:
def strongest_pokemon(db, type = None, generation = None): pokemon_list = list(db.keys()) if type: pokemon_list = pokemon_by_types(db, type) final_pokemon_list = [] if generation: for pokemon in pokemon_list: if db[pokemon][-2] == generation: final_pokemon_list.append(pokemon) else: final_pokemon_list = pokemon_list pokemon_strength_dict = {} for pokemon in final_pokemon_list: pok = db[pokemon] pokemon_strength_dict[pokemon] = pok[3] + pok[4] + pok[5] max_strength = 0 for pokemon in pokemon_strength_dict: if max_strength
def fastest_type(db): types = get_types(db) avg_speed = {} for type in types: avg_speed[type] = [] for type in types: for pokemon in db: if db[pokemon][1]: avg_speed[db[pokemon][1]].append(db[pokemon][-3]) if db[pokemon][2]: avg_speed[db[pokemon[2]].append(db[pokemon][-3]) avg = 0 for type in types: if avg_speed[type]: avg_speed[type] = sum(avg_speed[type]) / len(avg_speed[type]) else: avg_speed[type] = 0 if avg
def pokemon_by_types(db, types): pokemon_list = {} for pokemon in db: if db[pokemon][1] and (types == db[pokemon][1]) and (not pokemon in types): pokemon_list.append(pokemon) if db[pokemon][2] and (types == db[pokemon][2]) and (not pokemon in types): pokemon_list.append(pokemon) if pokemon_list: pokemon_list.sort() return pokemon_list
Thank you in advance for I appreciate it!!
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) 45, 49, 49, 45, 1, False) "Bulbasaur 1, Grass Poison Note that name, typel, 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 (1 Poison 1, False), Bulb 49, 49, 45 Grass 45 (4 Fire 39, 52, 43, 65 1, False), "Charmander None (6, Fire Flying 78, 84, 78,100, 1, False), "Charizard" (146, Fire Flying 90, 100, 90, 90, 1, True) Moltres (169 Poison Flying 85, 90, 80, 130, 2, False), Crobat "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 databaseStep 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