Beginners Query - Simple counter problem
Ian Clark
iclark at mail.ewu.edu
Thu Sep 6 14:24:34 EDT 2007
Carsten Haese wrote:
> On Thu, 2007-09-06 at 11:00 -0700, Scott David Daniels wrote:
>> def d6(count):
>> result = 0
>> for die in range(count):
>> result += random.randint(1, 6)
>> return result
>
> This, of course, can be further improved into:
>
> def d6(count):
> return sum(random.randint(1, 6) for die in range(count))
>
My stab at it:
>>> def roll(times=1, sides=6):
... return random.randint(times, times*sides)
Ian
More information about the Python-list
mailing list