Beginners Query - Simple counter problem

Carsten Haese carsten at uniqsys.com
Thu Sep 6 14:14:10 EDT 2007


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

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list