求三位和放到列表里
求三位和放到列表里
a = [11,345,21,7]
b = []
for i in a:
sum = 0
ii = '|'.join(str(i))
iii = ii.split('|')
for x in iii:
sum += int(x)
b.append(sum)
print(b)
额。。。str 可以遍历。。。忘记了
for i in a:
sum = 0
for ii in str(i):
sum += int(ii)
b.append(sum)