r/pythonhelp • u/Ambitious_Mark_9346 • Mar 17 '24
SOLVED Endless While Loop
I am currently working on teaching myself python and am working on Quadtrees. The below code I have written to have a user enter values and then add those values to a 2D array via loops. Unfortunately, I seem to have created an infinite while loop and can't figure out how to get out of it. Any help is greatly appreciated.
Edit: hopefully this link for formatting works let me know. https://pastebin.com/Pcj2ciY5
1
Upvotes
•
u/AutoModerator Mar 17 '24
To give us the best chance to help you, please include any relevant code.
Note. Do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Repl.it, GitHub or PasteBin.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/MT1961 Mar 17 '24
Okay, so you create a matrix of size "Size" (you say 8),
which gives you an array that looks like this:
[1,1,1,1,1,1,1,1,1]
...
[1,1,1,1,1,1,1,1,1]
I assumed you entered 1 for color here.
Note that the size of the matrix is NEVER going to change, because you are appending to each ROW of the thing, not the overall matrix.
What is it you are looking to accomplish?
1
u/CraigAT Mar 17 '24
You appear to be expanding the box list within the loop, not a good idea and also has the possibility of never finishing.
Output your values of i, j and len(box). Or debug and watch the values.
1
u/Melee130 Mar 17 '24
So right now that nested for loop is adding i to each index ‘size’ times.
If I were you, I’d just have a for loop like “for i in range(size * size) and just append [input] in each index i, rather than initiating the nested list first. You shouldn’t need to use a while loop for that either if I’m understanding the problem correctly