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

i am kind of confuse on how to do these two function show_of_strength_game(db, t

ID: 3824148 • Letter: I

Question

i am kind of confuse on how to do these two function

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.

second fuction that i got stuck own

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.

Extra Credit top_team_with_best_attackers(db, size=6): Given a database of pokemon db and an integer size, determine the best team that can be made (based on their attack only). The team should always have size members unless the number of pokemon in the original database db is lower than size – in which case the team has to include all available pokemon but sorted based on their attack. Break ties asciibetically -- lower asciibetical sorting will come first, e.g. if a “Spearow” and an “Ekans” have the same attack power, an “Ekans” will be chosen before a “Spearow”. Return the team as a list of pokemon names sorted by the pokemon’s attack statistic.

Explanation / Answer

def show_of_strength_game(db, team1, team2):
len1 = len(team1)
len2 = len(team2)
  
score = len1-len2
if len1 > len2:
team1 = team1[:len2]
elif len2 > len1:
team2 = team2[:len1]
  
for i in range(0, len(team1)):
if db[team1[i]][4] < db[team2[i]][4]:
score -= 1
elif db[team1[i]][4] > db[team2[i]][4]:
score += 1
return score

def pokemon_by_types(db, pok_type):
pokemon_dict = {}
for pokemon in db:
if db[pokemon][1] and (db[pokemon][1] in pok_type) and (not pokemon in pokemon_dict):
pokemon_dict[pokemon] = db[pokemon]
if db[pokemon][2] and (db[pokemon][2] in pok_type) and (not pokemon in pokemon_dict):
pokemon_dict[pokemon] = db[pokemon]
return pokemon_dict

def strongest_pokemon(db, type = None, generation = None):
pokemon_list = list(db.keys())
if type:
pokemon_list = pokemon_by_types(db, type).keys()
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 < pokemon_strength_dict[pokemon]:
max_strength = pokemon_strength_dict[pokemon]

strong_pokemon = []
for pokemon in pokemon_strength_dict:
if pokemon_strength_dict[pokemon] == max_strength:
strong_pokemon.append(pokemon)
strong_pokemon.sort()
return strong_pokemon

# code link: https://pastebin.com/2vBFf874

def top_team_with_best_attackers(db, size = 6):
attack_dict = {}
for pokemon in db:
attack_dict[pokemon] = db[pokemon][4]
attack_list = sorted(attack_dict.items(), key=lambda x: x[1], reverse=True)
attack_list = attack_list[:size]
  
top_teams = [pokemon for pokemon, attack in attack_list]
return top_teams