<p>嗨,我想从一个列表中计算出增长率的百分比</p>
<pre><code>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.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(gnumbers)
print growth_rate
growth()
</code></pre>
<p>但这里给了我一个索引错误(gnumbers)“索引器错误,索引超出范围”</p>