calculations using elements within sublists

Viewed 30

I could REALLY use some help with this problem:

list = [[1, 300], [2,600], [4, 900]]

The first element of the pairs below is the year and the second is the cash at the end of that year.

If I'm trying to calculate the cash values for each year and the formula for cash value is sum(cash/(1 + rate)**year), how can I figure out that the cash value at the end of year is 0?

I've been trying to use the values within the sublists but it's not letting me. Is that the best approach?

1 Answers

if I understand you question then this should work

lists = [[1,300],[2,600],[4,900]] #can't be list because it already has a meaning
sums=list(range(len(lists))) #if you are only going to use it a few time it may be better to just put the len of list but this will be better if you digitizing a lot of data
for i in range(len(lists)):
    sums[i]=int(lists[i][1]/(1 + rate)**lists[i][0]) #I don't see what rate is in this
print(sums)
Related