0

I want to create a list which will list coordinates on a 50 by 50 grid. I have been able to set the x-value from 0 to 49, while maintaining the y-value as 0. When I try to reset the x-value back to 0, and increment the y-value by 1- my code does not work. Could you help?

(x,y)=(0,0)
lst = []

answer = True
for x in range (50):
    lst=lst+[(x,y)]
    if (x>=49): 
        (x,y)=(0,y+1)
        answer = True
print lst
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by griswolf
0

Your loop says for x in range(50): , so it will execute 50 times. You want to create a 50 by 50 grid, so you want it to have 2500 entries. How can you expect to create a data structure with 2500 entries if your loop executes only 50 times?

1

So... what you want is another loop nested inside the first loop. I'll say it in English:
loop over the x value, and for each x value, loop over the y value.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.