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?

lst = []

answer = True
for x in range (50):
    if (x>=49): 
        answer = True
print lst

Recommended Answers

All 2 Replies

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.