自己能力有限,希望有人可以探讨探讨,有什么好方法 谢谢啦,~,~
d = {1:10, 2:20, 3:30, 4:40, 5:50, 6:60}
x = [1, 3, 4]
sumkey = 0
for i in d.keys():
if i in x:
print(f'{i} : key is present')
sumkey += d.get(i)
else:
print(f'{i} : key is not present.')
print(f'The sum of corresponding values for present keys are: {sumkey}')
d={1:10,2:20,3:30,4:40,5:50,6:60}
x = [1,3,4]
total = 0
for i in d:
if i in x:
total += d[i]
print(f"{i}:is present")
else:
print(f"{i}:is not present")
print(total)