这个 block 代码给我这个错误'TypeError: 'int' object is not an iterator'。我找不到问题所在,因为我有一个几乎完全相同的程序,而且运行良好。
else:
v3=r
for h in range(0,len(oddnums)):
if v1+v2+v3+v4==totalvals:
temp=[v1,v2,v3,v4]
combinations.append(temp)
else:
next(h)
print()
这里是完整的源代码: 全局奇数 全局温度 全局组合 全局组合 全局经济 全局总值 全局范围 全局 v4
for i in range (0 ,len(oddnums)):
v1=oddnums[i]
if i>=totalvals:
next(i)
print()
else:
print("v1")
#print(v1)
for x in range (0,len(oddnums)):
v2=oddnums[x]
print('v2')
total=x+i
if total >=totalvals:
next(x)
print()
else:
rem=totalvals-(x+i)
if rem<4:
next(x)
print()
else:
print()
for r in range (0,len(oddnums)):
#print('v3')
count += 1
#print(count)
lrem = rem - oddnums[r]
if lrem<1:
next(r)
print('no val')
else:
v3=r
for h in range(0,len(oddnums)):
if v1+v2+v3+v4==totalvals:
temp=[v1,v2,v3,v4]
combinations.append(temp)
else:
next(h)
print()
my_method()
完整错误信息:
追溯(最近的调用最后): 你好 文件“C:/Users/willf/Documents/Transition Task/question1/src/com/companyBoolean/4waycombo.py”,第 92 行,在 v1 我的方法() v2
文件“C:/Users/willf/Documents/Transition Task/question1/src/com/companyBoolean/4waycombo.py”,第 84 行,在 my_method 中 下一个(小时) TypeError: 'int' 对象不是迭代器
进程结束,退出代码为 1
请您参考如下方法:
问题在于尝试使用 next(i) 和 next(x)。 i 和 x 是由 range 迭代器生成的整数,而不是迭代器本身。
将这些行更改为 continue,您应该没问题。
