定义一个字典,其中字典的键是宝藏名,值是宝藏的金币数,即:dic1={‘宝藏1’:800,’宝藏2’:1200, ‘宝藏3’:2000,’宝藏4’:300, ‘宝藏5’:500,’宝藏6’:1000}现在要把’宝藏7’ 和它对应的金币数600,添加到字典中,应该用下面哪个语句:
A. dic1={'宝藏7':600}
B. dic1('宝藏7':600)
C. dic1('宝藏7')=600
D. dic1['宝藏7']=600
查看答案
定义一个字典,其中字典的键是宝藏名,值是宝藏的金币数,即:dic1={‘宝藏1’:800,’宝藏2’:1200, ‘宝藏3’:2000,’宝藏4’:300, ‘宝藏5’:500,’宝藏6’:1000}现在要删除’宝藏2:1200‘这条信息,应该用下面哪个语句:
A. del dic1{'宝藏2'}
B. del dic1['宝藏2']
C. del dic1['宝藏2:1200']
D. del dic1[1200]
字典dic1={‘宝藏1’:800, ‘宝藏2’ :1200, ‘宝藏3’ :2000, ‘宝藏4’ :300,‘宝藏5’ :500, ‘宝藏6’ :1000, ‘宝藏7’ :600} 下面哪个程序可输出如下的格式:宝藏1 800宝藏2 1200宝藏3 2000宝藏4 300宝藏5 500宝藏6 1000宝藏7 600
A. dic1={‘宝藏1’:800,’宝藏2’:1200, ‘宝藏3’:2000,’宝藏4’:300, ‘宝藏5’:500,’宝藏6’:1000}for d in dic1:print(d)
B. dic1={‘宝藏1’:800,’宝藏2’:1200, ‘宝藏3’:2000,’宝藏4’:300, ‘宝藏5’:500,’宝藏6’:1000}for d in dic1:print(dic1[d])
C. dic1={‘宝藏1’:800,’宝藏2’:1200, ‘宝藏3’:2000,’宝藏4’:300, ‘宝藏5’:500,’宝藏6’:1000}for d in dic1:print(d,dic1[d])
D. 以上都不对
把各宝藏的相关信息保存在下面的字典result中:result={‘宝藏数’: 7,‘宝藏列表’: [{‘宝藏名称’: ‘宝藏1’,’所在城堡’: ‘修加特’, ‘坐标’:{‘x’: 20, ‘y’: 500}, ‘收入’:800},{‘宝藏名称’: ‘宝藏2’,’所在城堡’: ‘卢云’, ‘坐标’:{‘x’: -20, ‘y’: 260}, ‘收入’:1200},{‘宝藏名称’: ‘宝藏3’,’所在城堡’: ‘古鲁丁’, ‘坐标’:{‘x’:-150, ‘y’:-50}, ‘收入’:2000},{‘宝藏名称’: ‘宝藏4’,’所在城堡’: ‘狄恩’, ‘坐标’:{‘x’:-50, ‘y’:-400}, ‘收入’:300},{‘宝藏名称’: ‘宝藏5’,’所在城堡’: ‘高达德’, ‘坐标’:{‘x’:100, ‘y’:300}, ‘收入’: 500},{‘宝藏名称’: ‘宝藏6’,’所在城堡’: ‘亚丁’, ‘坐标’:{‘x’:150, ‘y’:120}, ‘收入’: 1000},{‘宝藏名称’: ‘宝藏7’,’所在城堡’: ‘奇岩’, ‘坐标’:{‘x’:-100, ‘y’:-100}, ‘收入’:600},] }如果要输出result中的宝藏数,可以用下面哪个语句实现:
A. print('宝藏数')
B. print(result('宝藏数'))
C. print(result{'宝藏数'})
D. print(result['宝藏数'])
把各宝藏的相关信息保存在下面的字典result中:result={‘宝藏数’: 7,‘宝藏列表’: [{‘宝藏名称’: ‘宝藏1’,’所在城堡’: ‘修加特’, ‘坐标’:{‘x’: 20, ‘y’: 500}, ‘收入’:800},{‘宝藏名称’: ‘宝藏2’,’所在城堡’: ‘卢云’, ‘坐标’:{‘x’: -20, ‘y’: 260}, ‘收入’:1200},{‘宝藏名称’: ‘宝藏3’,’所在城堡’: ‘古鲁丁’, ‘坐标’:{‘x’:-150, ‘y’:-50}, ‘收入’:2000},{‘宝藏名称’: ‘宝藏4’,’所在城堡’: ‘狄恩’, ‘坐标’:{‘x’:-50, ‘y’:-400}, ‘收入’:300},{‘宝藏名称’: ‘宝藏5’,’所在城堡’: ‘高达德’, ‘坐标’:{‘x’:100, ‘y’:300}, ‘收入’: 500},{‘宝藏名称’: ‘宝藏6’,’所在城堡’: ‘亚丁’, ‘坐标’:{‘x’:150, ‘y’:120}, ‘收入’: 1000},{‘宝藏名称’: ‘宝藏7’,’所在城堡’: ‘奇岩’, ‘坐标’:{‘x’:-100, ‘y’:-100}, ‘收入’:600},] }如果要输出宝藏3所在的城堡名称,可以用下面哪个语句实现:
A. print(result('宝藏列表')[3]('所在城堡'))
B. print(result['宝藏列表'][3]('所在城堡'))
C. print(result('宝藏列表')[2]('所在城堡'))
D. print(result['宝藏列表'][2]['所在城堡'])