+ 2

How do i make so that it picks a random value from the list

Trying to make a single game and I cant seem to figure out or find anywhere that explains it, I only found random.randint() which displays a random int. Example, A list with three colours and when the code is run it displays one of three colours picked randomly

14th Jan 2020, 9:58 PM
Half
Half - avatar
3 Antworten
+ 6
You can use random.randint(to get a random index), but a better way is to use random.choice(). The only parameter provided to random.choice() is the list to be used. It will then get a random item from that list.
14th Jan 2020, 9:59 PM
Jianmin Chen
Jianmin Chen - avatar
+ 3
Thank you so much this means so much <333
14th Jan 2020, 10:10 PM
Half
Half - avatar
+ 3
This question has been asked multiple times before, use the searchbar next time please. Kindly delete this post as it is a duplicate. Read more here: https://www.sololearn.com/discuss/1316935/?ref=app
14th Jan 2020, 10:22 PM
Aymane Boukrouh
Aymane Boukrouh - avatar