I want to enter a number in the input and get the number of occurrences of one in its binary basis
print(str({int(input()):'b'}).count('1'))
The code I wrote is like this, but for example:
input:3
output:0
That is wrong
CodePudding user response:
Proceed as follows:
print("{:b}".format(int(input())).count('1'))
input:3
output:2