python code to select all probability -


python code select probability in (test)

i use code code:

test = ["test1", "test2", "test3", "test4", "test5"]  dx = random.choice(test)  x in range(0, 5):     print(dx) 

it's print me this: test1(5 times) or test2(5 times) , soo on .....

and code :

test = ["test1", "test2", "test3", "test4", "test5"]  x in test:     print(x) 

didn't work.

are there code choice thing (test1, test2, test3, test4, test5)

thanks ....

test = ["test1", "test2", "test3", "test4", "test5"]  # selects random value , stores in dx. dx = random.choice(test)  x in range(0, 5):     # prints value stored in dx.     print(dx) 

do see problem? code selected random value once, prints same value 5 times. fix it, need select new value each loop:

test = ["test1", "test2", "test3", "test4", "test5"]  x in range(0, 5):     # selects random value , stores in dx.     dx = random.choice(test)     # prints value stored in dx.     print(dx) 

or more simply:

test = ["test1", "test2", "test3", "test4", "test5"]  x in range(5):     print(random.choice(test)) 

also take care of variables names. it's recommended use lower case, underscores when need spaces, , name them based on should contain. "test" not descriptive , may give people hard time understand code when it's used.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -