+ 1

I'm having a problem using the random.choice() python command. What should I do?

When I try to use random.choice() in order to take a random element from a list, I get a name error , saying that "random" is not defined. I know that random.choice() generally works on other python platforms. Do you know why it doesn't work or have a solution to make it work? I f not , I'd appreciate if you had an alternative to recommend. https://code.sololearn.com/314/#py

27th Dec 2018, 9:01 PM
dimitris9
5 Respostas
+ 3
Put import random At the top
27th Dec 2018, 9:14 PM
Taste
Taste - avatar
+ 3
Are you importing the “random” module? For example (at the top of your code): import random I am unable to see the code you shared so I’m just guessing based on the description you gave.
27th Dec 2018, 9:14 PM
Diego
Diego - avatar
+ 3
The code you shared is python code in a Swift emulator 🤔
27th Dec 2018, 9:37 PM
Anna
Anna - avatar
+ 2
Thank you for your help! I'm new to python and sometimes I even forget to do basic things.
27th Dec 2018, 9:20 PM
dimitris9
+ 1
If you want, check the fake ID Generator I made using random.choice!https://code.sololearn.com/chWRFUKJeVyu/#py
27th Dec 2018, 9:57 PM
dimitris9