Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting repetitions of one in the base 2 representation of a number python

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Proceed as follows:

   print("{:b}".format(int(input())).count('1'))

input:3
output:2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading