我的代码如下:
{'Bug Out Bag': ['q', 0.25, 100], 'XM': ['q', 0.25, 10]}
print('{}'.format(float(addition1)+float(addition2)) )
我收到错误:
addition1 = coins_in_the_bag[0]
KeyError: 0
谢谢!
答案 0 :(得分:1)
coins_in_the_bag = {'Bug Out Bag': ['q', 0.25, 100], 'XM': ['q', 0.25, 10]}
coins_in_the_bag
是dict
。使用诸如
>>> coins_in_the_bag['Bug Out Bag']
# ['q', 0.25, 100]
>>> coins_in_the_bag['XM']
# ['q', 0.25, 10]
此外,coins_in_the_bag['Bug Out Bag']
会返回一个列表。警惕在号码上拨打float
,而不是整个列表