【发布时间】:2011-04-06 10:58:56
【问题描述】:
为什么我会收到“无法将序列乘以'float'类型的非整数”的错误?来自以下代码:
def nestEgVariable(salary, save, growthRates):
SavingsRecord = []
fund = 0
depositPerYear = salary * save * 0.01
for i in growthRates:
fund = fund * (1 + 0.01 * growthRates) + depositPerYear
SavingsRecord += [fund,]
return SavingsRecord
print nestEgVariable(10000,10,[3,4,5,0,3])
【问题讨论】:
-
我更喜欢
SavingsRecord.append(fund)而不是你的SavingsRecord += [fund,],它可能会更快。 -
@StephanWeinhold ,该帖子的日期为 2012 年。此问题发布于 2010 年。
-
@raoulbia 对不起!恐怕我把身份证弄混了。感谢您的关注!
标签: python floating-point sequence