回答here。
1.首先我创建了变量POWER
、gandalf
和saruman
,如上面代码中所示,然后创建了一个名为spells
的变量来存储巫师施放的法术数量
代码
POWER = {
'Fireball': 50,
'Lightning bolt': 40,
'Magic arrow': 10,
'Black Tentacles': 25,
'Contagion': 45
}
gandalf = ['Fireball', 'Lightning bolt', 'Lightning bolt', 'Magic arrow', 'Fireball',
'Magic arrow', 'Lightning bolt', 'Fireball', 'Fireball', 'Fireball']
saruman = ['Contagion', 'Contagion', 'Black Tentacles', 'Fireball', 'Black Tentacles',
'Lightning bolt', 'Magic arrow', 'Contagion', 'Magic arrow', 'Magic arrow']
spells=10
gandalf_wins=0
saruman_wins=0
gandalf_power=[]
saruman_power=[]
我在这里被绊住了,因为我不知道如何为每一个单词创建一本字典,里面都有拼写和拼写的力量。那么,我应该如何比较它们呢?提前谢谢
我认为这些步骤说明得非常清楚,使用
for
循环就足以解决第三部分对于第四部分,您可以使用
zip
,同时对这两个列表进行整理下面是使用zip来循环法术,并比较每轮法术的威力
您应该参考Python字典。它们就像列表和元组,只是不同之处在于它们就像数据库的表,其中有用于存储不同值的行和列
https://www.w3schools.com/python/python_dictionaries.asp 请参阅此以获取帮助
相关问题 更多 >
编程相关推荐