[Tutor] Creating Adventure Games Python Port - Chapter 2

Kent Johnson kent37 at tds.net
Mon Oct 2 03:44:05 CEST 2006


Dick Moores wrote:
> Works fine, but instead of
> coin1 = random.randint(1, 10)
> coin2 = random.randint(1, 10)
> 
> you could simplify by using
> coin1 = random.randrange(2)
> coin2 = random.randrange(2)

or maybe random sample:
In [22]: random.sample(('heads', 'tails'), 1)[0]
Out[22]: 'tails'

Kent



More information about the Tutor mailing list