我有一个有60个元素的列表,现金流。我正在构建一个新列表ListNPV,其中每个元素都是使用原始现金流中每个元素的等式的结果。在将总和添加到新列表后,我从原始现金流中删除一个元素。在
当我运行这个程序时,它正好完成了列表的一半,所以有30个值。把结果从45/30翻了一番。我要0/60。使用顶棚。在
for payment in CashFlow:
NPV = 0
for i in range(len(CashFlow)):
NPV += CashFlow[i] / (1+MonthlyInterest)**i
NPV = round (NPV, 0)
ListNPV.append(NPV)
CashFlow.remove(payment)
print 'CashFlow = ', CashFlow
print 'ListNPV =', ListNPV
由于以下线路
线以上影响现金流。删除这一行,所有的迭代都将完成。之后,您可以单独删除现金流列表。在
从the python docs开始,不应更改正在迭代的列表:
在本例中,您甚至不使用循环变量
payment
,因此您可以稍微清理一下循环。这应该是有效的:相关问题 更多 >
编程相关推荐