Home > Software design >  Trying to figure out the equivalent of C arrays in Python
Trying to figure out the equivalent of C arrays in Python

Time:10-31

My code is:

for X in range(16):
    appleX = 0
    middleTileX = -350   (distance/2)
    appleX[X]  = middleTileX   distance*X

and I'm trying to get a list of 16 numbers and store them on appleX, I then want to run so that a randomizer will pick a random number on the list (let's say number 5) and then it will look on the 5th stored number in the "array" or list in python. The 5th number should be the answer of

     middleTileX   distance*5

but I don't want to calculate and write all of the 16 numbers and I have found no way of automatically assigning values to a list.

I haven't tried much as none of the answers on the internet seems to be the right one

CodePudding user response:

You just need list comprehension.

I'm trying to get a list of 16 numbers and store them on appleX, I then want to run so that a randomizer will pick a random number on the list (let's say number 5) and then it will look on the 5th stored number in the "array" or list in python.

result = [middleTitleX   distance*i for i in range(16)]

CodePudding user response:

You can use The random library in python it's easy, check this link here for more information.

  • Related