Rubykuby

Benford's law applied to square numbers #2

May 28th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. maxvalue = 10**4
  2. benfordList = [[0], [0], [0], [0], [0], [0], [0], [0], [0]]
  3.  
  4. for i in range(1, maxvalue+1):
  5.     for first in range(1, 10):
  6.         if str((i)**2).startswith(str(first)):
  7.             benfordList[first-1][0] += 1
  8.  
  9. for i in range(len(benfordList)):
  10.     print("Numbers starting with ", i+1, ": ", benfordList[i][0], sep='')
  11.     print("Percentage of total:     ", benfordList[i][0] / maxvalue * 100, " %", sep='')
Advertisement
Add Comment
Please, Sign In to add comment