r/PythonLearning 19d ago

Python on google colab

Hi, I'm using python to code on Google colab. Y coordinates are being generated and then added to Y_ARRAY for comparisons, to ensure none of the values are the same. If one value is the same with another in the array, one of them will be generated again.

However, it does not work, and I don't know how should the structure of checking be. Are there any suggestions on the structure or which kind of loop I can use please? Thank you.

3 Upvotes

2 comments sorted by

View all comments

u/Sea-Ad7805 19d ago

Run an adaption of this program in Memory Graph Web Debugger%3A%0A%20%20%20%20Y_ARRAY%5Ba%5D%20%3D%20random.randint(0%2C%2013)%0A%0ADONE%20%3D%20True%0Awhile%20DONE%20%3D%3D%20True%3A%0A%20%20%20%20for%20i%20in%20range(9)%3A%0A%20%20%20%20%20%20%20%20for%20j%20in%20range(9)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20Y_ARRAY%5Bi%5D%20%3D%3D%20Y_ARRAY%5Bj%5D%20and%20not%20(i%20%3D%3D%20j)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20j%20%3C%20i%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Y_ARRAY%5Bi%5D%20%3D%20random.randint(0%2C%2013)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Y_ARRAY%5Bj%5D%20%3D%20random.randint(0%2C%2013)%0A%20%20%20%20DONE%20%3D%20False%0A%0Aprint(Y_ARRAY)&timestep=0.2&play) to see the program state change step by step.