Please help ASAP with these two functions. Their examples are given as well... P
ID: 3823538 • Letter: P
Question
Please help ASAP with these two functions. Their examples are given as well... PYTHON
Example "info" file: ID Name Type 1" Type 2 Generation Legendary 1, "Bulbasaur", Grass Poison 1, "FALSE" 6, "Charizard "Fire 4, "Charmander Fire FALSE" 169, "Crobat Poison Flying", 2, "FALSE" 146, "Moltres Fire Flying", "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, 1000 146,90,100, 90,90 149,91,134, 95,80 641,79,115, 70,111 643,100, 120,100,90Explanation / Answer
def count_by_type(db, type):
single_type_count = 0
dual_type_count = 0
for key in db:
if (
db[key][2] != None and
(db[key][1] == type or db[key][2] == type) ):
dual_type_count += 1
elif (db[key][1] == type):
single_type_count += 1
return (
single_type_count, dual_type_count,
single_type_count + dual_type_count )
def pokemon_by_hp_defense(db, lowest_hp, lowest_defence):
selected = {}
for key in db:
if (db[key][3] >= lowest_hp and
db[key][5] >= lowest_defence):
selected[key] = db[key]
return selected
// Put your DB here
print count_by_type(sample_db, "Fire")
print pokemon_by_hp_defense(sample_db, 30, 72)
Cheers,
PH