Want more features on Pastebin? Sign Up, it's FREE!
Guest

Sum over 2

By: misingnoglic on Feb 26th, 2013  |  syntax: Python  |  size: 0.47 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data