I have 2 lists:
a=[0,1,5,7]
b=[2,10,6,3]
I need to get this list :
c=[(b[0]+a[0]),(b[0]+b[1]),(b[0]+b[1]+b[2]),(b[0]+b[1]+b[2]+b[3])]
I tried doing this using a for loop:
c=[(b[0]+a[0])]
for i in range(0,(len(b)-1)):
for p in range(i+1,len(b)):
if i==0:
c.append((b[i]+b[p]))
else:
c.append((c[i]+b[p]))
I am supposed to get [2,12,18,21] but I am getting [2, 12, 12, 12, 18, 15, 15]
Where am I going wrong in the for loops?
Thank you :)