Skip to content
CodeItRaw
Code Reading
/
Count the Ones
Path
Play
Daily
Leaderboard
tr
Bug Hunt
Count the Ones
It should count the 1s in n's binary form, but for n > 0 it never stops. Find the line and the kind of bug.
Click the line you think is wrong.
1
def
count_ones
(n):
2
count =
0
3
while
n >
0
:
4
count += n &
1
5
n <<=
1
6
return
count