Advertisement
misingnoglic

Sum over 2

Feb 26th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. from random import randrange
  2.  
  3. Sum=0
  4. count=0
  5. L=[] #list that will contain the counts
  6.  
  7. while True: #infinite loop
  8.     while Sum<2:
  9.         Sum+=randrange(0,2) #picks a random number from 0 and 1
  10.         count+=1 #counts every time it does this until the sum is more than 2
  11.     L+=[count] #adds the count to the list
  12.     print(sum(L)/len(L)) #prints the average of all the numbers of the list
  13.     Sum=0 #
  14.     count=0 #resets the sum and count to create more counts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement