I am getting a "TypeError: cannot unpack non-iterable int object"

Jayan Paliwal :

I am having some problem. I would be very grateful if somebody please helps me out.

This is the code :

def next1(n1, r1, c1, grid1):
    p_x, p_y = 0 # >>> TypeError: cannot unpack non-iterable int object
    for i in range(0, n1):
        for x in range(0, n1):
            if grid1[i][x] == "p":
                p_x = i
                p_y = x
    diff_x = abs(r1-p_x)
    diff_y = abs(c1-p_y)
    if diff_x > diff_y:
        if r1-p_x > 0:
            return "UP"
        else:
            return"DOWN"
    else:
        if c1-p_y > 0:
            return"LEFT"
        else:
            return"RIGHT"


n = int(input())
r, c = [int(i) for i in input().strip().split()]
grid = []
for i in range(0, n):
    grid.append(list(input()))
grid[r][c] = "m"
print(next1(n, r, c, grid)) # >>> TypeError: cannot unpack non-iterable int object

This is the exact error :

    Traceback (most recent call last):
      File "C:/Users/DELL/PycharmProjects/start/bot.py", line 28, in <module>
        print(next1(n, r, c, grid))<br/>
      File "C:/Users/DELL/PycharmProjects/start/bot.py", line 2, in next1
        p_x, p_y = 0
    TypeError: cannot unpack non-iterable int object

How can I resolve this error?

Andbdrew :

try px = py = 0 on that line instead (or just define those values in separate statements)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related