小编Tyc*_*sma的帖子

计算增长率

您好,我正在尝试计算列表中的增长率(以百分比表示)

def growth():

   population = [1, 3, 4, 7, 8, 12]

   # new list for growth rates
   growth_rate = []

   # for population in list
   for pop in population:

       gnumbers = ((population[pop] - population[pop-1]) / population[pop-1] * 100)
       growth_rate.append(gnumbers)
       print growth_rate

growth()
Run Code Online (Sandbox Code Playgroud)

但它在这里给了我一个索引错误(gnumbers)“IndexError,索引超出范围”

python python-2.7

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-2.7 ×1