cấp: mới bắt đầukhông thể nhân chuỗi bởi non-int thuộc loại 'float'
tại sao tôi gặp lỗi "không thể nhân chuỗi bởi non-int của loại '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])
nhờ Baba
Tôi muốn 'SavingsRecord.append (fund)' thay vì 'SavingsRecord + = [quỹ,] ', nó * có thể * nhanh hơn. –
Có thể trùng lặp với [Tại sao tôi nhận được TypeError: không thể nhân chuỗi bởi non-int của loại 'float'?] (https://stackoverflow.com/questions/485789/why-do-i-get-typeerror-cant-multiply-sequence-by-non-int-of-type-float) –
@StephanWeinhold, bài đăng đó là ngày 2012. Câu hỏi này đã được đăng trong năm 2010. – raoulbia