Shuffle

Seymore4Head Seymore4Head at Hotmail.invalid
Sat Sep 13 22:10:08 EDT 2014


On Sat, 13 Sep 2014 19:32:55 -0600, Michael Torrie <torriem at gmail.com>
wrote:

>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.

Thanks.





More information about the Python-list mailing list