0

我得到TypeError: 'int' object is not iterable下面的代码,为什么?

def temp_media(c, l):
    c_ini = c
    l_ini = l
    res_vert = 0
    res_horiz = 0
    dim = dimensoes()
    c_max = dim[0] // 2
    l_max = dim[1]
    for l in l_max:
        for c in c_max:
            res_vert = res_vert + calcula_temp(c, l)
        res_horiz = res_horiz + calcula_temp(c, l)
    return (((res_horiz / (c_max - c_ini)) + (res_vert / (l_max - l_ini))) / 2)

我怎样才能解决这个问题?

4

1 回答 1

2

您需要在 for 循环中使用range(或xrange在 python 2 中):

c_max = dim[0] // 2
l_max = dim[1]
for l in range(l_max):
    for c in range(c_max):
于 2012-11-04T20:38:32.847 回答