can't multiply sequence by non-int of type 'float'

后端 未结 6 1192
傲寒
傲寒 2020-12-15 03:22

level: beginner

why do i get error \"can\'t multiply sequence by non-int of type \'float\'\"?

def nestEgVariable(salary, save, growthRates):
    Sav         


        
6条回答
  •  天涯浪人
    2020-12-15 04:03

    for i in growthRates:  
        fund = fund * (1 + 0.01 * growthRates) + depositPerYear
    

    should be:

    for i in growthRates:  
        fund = fund * (1 + 0.01 * i) + depositPerYear
    

    You are multiplying 0.01 with the growthRates list object. Multiplying a list by an integer is valid (it's overloaded syntactic sugar that allows you to create an extended a list with copies of its element references).

    Example:

    >>> 2 * [1,2]
    [1, 2, 1, 2]
    

提交回复
热议问题