Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 817
Jayan Paliwal Avatar asked Nov 29 '25 00:11

Jayan Paliwal


1 Answers

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

like image 93
Andbdrew Avatar answered Nov 30 '25 14:11

Andbdrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!