我一直在为计算2个不同列表中的值的平均值而挣扎。这是我一直在做的事情(作为python新手):计算平均值
Averagelist = []
Listofvalues1 = ['1', '2', '3', '4']
Listofvalues2 = ['5', '6', '7', '8']
for i, x in enumerate(Listofvalues1):
for j, y in enumerate(Listofvalues2):
if j == i:
AVGvalue = (int(x)+int(y)/2)
Averagelist.append(AVGvalue)
我自己想出了这个方法。它可能是无用的,但到目前为止,我可以打印两个值,我想用于计算,但我得到一个错误“ValueError:无效的文字为int()与基10:'somevalue'”。难道是''
的标志?
干杯!
显示Listofvalues1'和'Listofvalues2'的'内容。 – Barmar 2014-09-01 13:38:01