In your code, list list1 never gets emptied. There is another problem : the doc for random.randrange() says it "choose[s] a random item from range(start, stop[, step])" and range(1, 19) goes from 1 included to 19 _not_ included. Your 'd20' is not a 20-sided dice.
On Mon, Nov 16, 2009 at 8:18 PM, <kb1...@aim.com> wrote: > > > Hello Tutor list. > I'm running a test to find what the experimental average of a d20 is, and > came across a strange bug in my code. > import random > list1 = [] > def p(): > d = 0 > for number in range(1,1000): > t = random.randrange(1,19) > list1.append(t) > for value in list1: > d+=value > print d/1000 > d = 0 > for value in range(1,100): > p() > > It works, but I have a logic error somewhere. It runs, and the results have > a pattern : > 9 > 19 > 28 > 37 > 47 > 56 > 66 > 75 > 85 > 94 > 104 > 113 > ... > ... > It just adds 10, and every second result, subtracts 1, till it gets to 0, > and then starts again with 9 in singles, and whatever in the 10's, etc. > What is causing this? > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor