【发布时间】:2019-06-05 04:14:09
【问题描述】:
问题的目标是:
实例化一个名为
pokedex的空字典定义一个新函数,该函数将接受
pokedex, poke_id, poke_name, poke_type的参数使用我的字典函数
create_pokemon并在pokedex字典中添加一个新的key:value对,其中key是poke_id,value是新创建的口袋妖怪字典
我创建了一个字典函数:create_pokemon(poke_id, poke_name, poke_type)。密钥是'hp','defense', 'special_defense',名单还在继续。
这是我的create_pokemon 函数:
new_pokemon= {
'poke_id': poke_id,
'poke_name': poke_name,
'poke_type': poke_type,
'hp': np.random.randint(400,501),
'attack': np.random.randint(50,101),
'defense': np.random.randint(50,101),
'special_attack' : np.random.randint(100,151),
'special_defense': np.random.randint(100,151),
'speed': np.random.randint(0,101)
}```
so when I display pokedex, it should look something like:
```{1: {'attack': 64,
'defense': 59,
'hp': 495,
'poke_id': 1,
'poke_name': 'charmander',
'poke_type': 'fire',
'special_attack': 100,```
【问题讨论】:
-
您只是想弄清楚将字典添加到另一个字典的语法吗?
-
This is my create_pokemon function: 看不到任何功能...
标签: python function dictionary key