[Tutor] Creating Adventure Games Python Port - Chapter 2
John Fouhy
john at fouhy.net
Mon Oct 2 03:58:17 CEST 2006
On 02/10/06, Kent Johnson <kent37 at tds.net> wrote:
> or maybe random sample:
> In [22]: random.sample(('heads', 'tails'), 1)[0]
> Out[22]: 'tails'
I think random.choice would be a better option here:
>>> random.choice(['heads', 'tails'])
'tails'
>>> [random.choice(['heads', 'tails']) for i in range(10)]
['tails', 'tails', 'heads', 'tails', 'tails', 'tails', 'heads',
'heads', 'heads', 'heads']
--
John.
More information about the Tutor
mailing list