Question
Follow up from last python question about Pokemon(sent by accident). get_types(db): Given a database db, this function determines all the pokemon types in the database.
Follow up from last python question about Pokemon(sent by accident).
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. Databases for function.
def db1(): return {'Bulbasaur':(1,'Grass','Poison',45,49,49,45,1,False), 'Reshiram':(643,'Dragon','Fire',100,120,100,90,5,True), 'Charizard':(6,'Fire','Flying',78,84,78,100, 1,False), 'Charmander':(4,'Fire',None,39,52,43,65,1,False), 'Tornadus, (Incarnate Form)':(641,'Flying',None,79,115,70,111,5,True) }
def db2(): return {'Torkoal':(324,'Fire',None,70,85,140,20,3,False), 'Pansear':(513,'Fire',None,50,53,48,64,5,False), 'Charmander':(4,'Fire',None,39,52,43,65,1,False), 'Entei': (244,'Fire',None,115,115,85,100,2,True) } def db3(): return{'Charizard':(6,'Fire','Flying',78,84,78,100, 1,False), 'Moltres':(146,'Fire','Flying',90,100,90,90,1,True), 'Ho-oh':(250,'Flying','Fire',106,130,90,90,2,True) }
def db4(): return {'Bulbasaur':(1,'Grass','Poison',45,49,49,45,1,False), 'Reshiram':(643,'Dragon','Fire',100,120,100,90,5,True), 'Entei': (244,'Fire',None,115,115,85,100,2,True), 'Charmander':(4,'Fire',None,39,52,43,65,1,False), 'Tornadus, (Incarnate Form)':(641,'Flying',None,79,115,70,111,5,True), 'Ho-oh':(250,'Flying','Fire',106,130,90,90,2,True), 'Primeape': (57, 'Fighting', None, 65, 105, 60, 95, 1, False), 'Mantyke': (458, 'Water', 'Flying', 45, 20, 50, 50, 4, False), 'Lombre': (271, 'Water', 'Grass', 60, 50, 50, 50, 3, False), 'Virizion': (640, 'Grass', 'Fighting', 91, 90, 72, 108, 5, True), 'Volcanion': (721, 'Fire', 'Water', 80, 110, 120, 70, 6, True), 'Arcanine': (59, 'Fire', None, 90, 110, 80, 95, 1, False) }
def db6(): return { 'A': (1, 'Fire','Rock', 10, 20, 30, 40, 1, True), 'B': (1, 'Water',None, 10, 20, 30, 80, 2, False), 'C': (1, 'Ground','Fire', 10, 20, 30, 55, 3, True), 'D': (1, 'Water','Rock', 10, 20, 30, 37, 4, False), 'E': (1, 'Fire',None, 10, 20, 30, 102, 5, True), 'F': (1, 'Water',None, 10, 20, 30, 80, 6, False), }
def db7(): return { 'A': (1, 'Fire','Grass', 10, 20, 30, 66, 1, True), 'B': (1, 'Water','Ice', 10, 20, 30, 66, 2, False), 'C': (1, 'Grass','Dragon', 10, 20, 30, 66, 3, True), 'D': (1, 'Dragon','Water', 10, 20, 30, 66, 4, False), 'E': (1, 'Ghost','Fire', 10, 20, 30, 66, 5, True), 'F': (1, 'Ice','Ghost', 10, 20, 30, 66, 6, False), }
Example runs:
db ={'Bulbasaur':(1,'Grass','Poison',45,49,49,45,1,False)}
>>>get_types(db)
['Grass','Poison']
>>>get_types(db2())
['Fire']
>>>get_types(db3())
['Fire','Flying']
>>>get_types(db1())
['Dragon','Fire','Flying','Grass','Poison']
>>>get_types({})
[]
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. The method .count is not allowed. Databases for this function same at the function above.
Example runs:
db ={'Bulbasaur':(1,'Grass','Poison',45,49,49,45,1,False)}
>>>count_by_type(db,'Grass')
(0,1,1)
>>>count_by_type(db2(),'Grass')
(0,0,0)
>>>count_by_type(db2(),'Fire')
(4,0,4)
>>>count_by_type(db3(),'Flying')
(0,3,3)
>>>count_by_type(db1(),'Fire')
(1,2,3)
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().
Example runs:
db ={'Primeape': (57, 'Fighting', None, 65, 105, 60, 95, 1, False)}
>>> fastest_type(db)
['Fighting']
db ={'Bulbasaur':(1,'Grass','Poison',45,49,49,45,1,False)}
>>>fastest_type(db)
['Grass','Poison']
>>>fastest_type(db1())
['Flying']
>>>fastest_type(db6())
['Fire','Water']
>>>fastest_type(db7())
['Dragon','Fire','Ghost','Grass','Ice','Water']
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.
Example runs:
db ={'Torkoal':(324,'Fire',None,70,85,140,20,3,False)}
>>>legendary_count_of_types(db)
{'Fire':0}
>>>legendary_count_of_types(db2())
{'Fire':1}
>>>legendary_count_of_types(db3())
{'Fire':2, 'Flying':2}
>>>legendary_count_of_types(db4())
{'Grass':1, 'Fire':4, 'Flying':2, 'Poison':0, 'Dragon': 1, 'Water':1, 'Fighting':1}
>>>legendary_count_of_types({})
{}
Step 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