Shuffle
Michael Torrie
torriem at gmail.com
Sat Sep 13 21:32:55 EDT 2014
On 09/13/2014 05:47 PM, Seymore4Head wrote:
> Here is a screenshot of me trying Dave Briccetti's quiz program from
> the shell and it (the shuffle command) works.
> https://www.youtube.com/watch?v=VR-yNEpGk3g
> http://i.imgur.com/vlpVa5i.jpg
>
> Two questions
> If you import random, do you need to "from random import shuffle"?
>
> Why does shuffle work from the command line and not when I add it to
> this program?
>
> import random
> import shuffle
> nums=list(range(1,11))
> shuffle(nums)
> print (nums)
>
> I get:
> No module named 'shuffle'
You can do it two ways:
Refer to it as random.shuffle()
or
from random import shuffle
I tend to use the first method (random.shuffle). That way it prevents
my local namespace from getting polluted with random symbols imported
from modules.
More information about the Python-list
mailing list