Advertisement
pfelix

count_2_occurrence

Sep 2nd, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.19 KB | None | 0 0
  1. # by Patrick Felix
  2. # number of occurrences of digit 2 between 0 and n-1
  3.  
  4. def count2(n):
  5.   aux = 0
  6.   for each in range(0, n):
  7.     xtwo = str(each).count('2')
  8.     aux += xtwo
  9.   return aux
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement