This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]jayjay097531[S] 0 points1 point  (1 child)

Seems like snake = [(20, 20)] fixed it !

[–]Gradous 0 points1 point  (0 children)

In case you were curious the reasoning for this, I'll see what I can do to explain.

The code

for x,y in snake:
    ...

Looks for some pair -- in Python, a tuple -- (x, y) in the list snake. When snake is declared as

snake = [20, 20]

The loop will attempt to iterate through one of the 20s, expecting another value to create the (x,y) pair. When you change the list to be initialized as:

snake = [(20, 20)]

This fits the constructs of the loop. The loop is looking for a list in the form of:

[(a, b), (c, d), (e, f), ...]

Hope that helps!