我正在寫一個程序,它可以計算列表(data1)中10個數字的最小值和最大值。我收到一個「類型錯誤:‘浮動’對象不是可迭代」爲下面幾行:TypeError:'float'對象不可迭代
temp_min10=min(data1[x-z][3])
temp_max10=max(data1[x-z][2])
全部程序:
x=int(0)
for line in data1:
if x>=9:
min10=0
max10=0
for z in range(0,10):
temp_min10 = temp_max10 = 0
temp_min10=min(data1[x-z][3])
if temp_min10<min10:
min10=temp_min10
temp_max10=max(data1[x-z][2])
if temp_max10>max10:
max10=temp_max10
d_chan.append([max10,min10])
else:
d_chan.append([0,0])
x+=1
感謝您的幫助!
向我們展示一個'data1'。另外,'int(0)'是什麼? – kindall
是的,絕對是一系列愚蠢的錯誤... data1是包含數字的列表的列表。我最初嘗試int(0),因爲我無法弄清float問題(現在有「x = 0」)。代碼應該遍歷一定數量的數字來確定最大值和最小值。我用一個簡單的函數解決了這個問題。 – user1079546