先看列表
假设
i = ["12","21"]
ls =[3,5]
如何让他变成
1×3+2×5,2×3+1×5
并且成一个新列表?
我写的完整的是这样的,但是他算出来不正确,所以是失败品
i = ["12","21"]
ls =[3,5]
j = 0
sum=0
for x in i:
sum= sum +int(x[j])*ls[j]
j=j+1
print(sum)
先看列表
假设
i = ["12","21"]
ls =[3,5]
如何让他变成
1×3+2×5,2×3+1×5
并且成一个新列表?
我写的完整的是这样的,但是他算出来不正确,所以是失败品
i = ["12","21"]
ls =[3,5]
j = 0
sum=0
for x in i:
sum= sum +int(x[j])*ls[j]
j=j+1
print(sum)
i = ['12', '21']
ls = [3, 5]
ret = []
for num in i:
mid = 0
for index in range(len(ls)):
mid += int(num[index]) * ls[index]
ret.append(mid)
print(ret)