题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
http://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#刚开始学写的
while True:
try:x = int(input())
count = 0
y = list(bin(x))
for i in y:
if i == '1':
count += 1
print(count)
except:
break
#做了50道题后写的
while True:
try:
x = int(input())
y = bin(x)
count1 = y.count('1')
print(count1)
except:
break
try:
x = int(input())
y = bin(x)
count1 = y.count('1')
print(count1)
except:
break