Python 3:计算 n 个值的百分比变化

Python 3: Calculating percentage change with n number of values

我有一个函数可以计算两个值之间的百分比增加/减少。函数中的参数是original_value和new_value.

问题:我需要程序获取 n 个值,例如六个值,然后 运行 对每对值执行函数。一个例子:

值是 1、2、3、4、5 和 6。然后我需要程序来计算平均值。 1 和 2、2 和 3、3 和 4、4 和 5 以及 5 和 6 之间的百分比变化。

我认为最好的方法是制作上述函数,然后 运行在每对值上使用该函数。问题是我应该如何让程序 运行 每对的函数(值/对的数量不同)?这些值由用户作为键盘输入输入。用户首先指定要输入多少个值,然后输入每个值。这些值存储在列表 atm 中。

def percentage_change():
    value_list = []
    number_of_values = int(input("How many values are there?"))
    counter = 0
    while counter < number_of_values:
        value = float(input("Enter value: "))
        value_list.append(value)
        counter += 1
    list_index = 0
    percentages = []
    while list_index < len(value_list) - 1:
        percentage_change = #execute whatever formula you want to use to calculate percentage change here
        percentages.append(percentage_change)
        list_index += 1
    #average percentages
    #print values