为什么我会收到 TypeError: 'int' object is not iterable? [已关闭]

问题描述 投票:0回答:1

我的代码:

t = int(input()) # t is the number of Test cases
score = 0
for i in t:
    for i in 10:
        c = input()
        d = list(c)
        if(d[0] == "X" or d[9] == "X"):
            score+=1
        if((i>0 and i<9) and (d[1] == "X" or d[8])):
            score+=2
        if((i>1 and i<8) and (d[2] == "X" or d[7])):
            score+=3
        if((i>2 and i<7) and (d[3] == "X" or d[6])):
            score+=4
        if((i == 4 or i == 5) and (d[4] == "X" or d[5] == "X")):
            score += 5

        print("Score is " + score +" woho")

错误:

   for i in t:
TypeError: 'int' object is not iterable
python for-loop typeerror
1个回答
1
投票

你不能迭代 int,你的对象必须是可迭代的。只需使用

for i in range(t)
range(t)
返回一个包含从 0 到 t-1 的整数的可迭代对象。

© www.soinside.com 2019 - 2024. All rights reserved.