how to get the count of no of times a digit has repeated in a given list?

Viewed 16

I tried to take a user input binary list and used the count function to get the number of times the number 0 has repeated. But for some reason it is always printing 0 as output. Why?

My code:

a = list(map(int, input().split()))
b = a.count(0)
print(b)
1 Answers

Try this to take user input of integer and print number of binary zeroes

def test(num):
    ones =  bin(num).replace("0b", "").count('1')
    zeros = bin(num).replace("0b", "").count('0')
    return "Number of zeros: " + str(zeros);

n = 344; 
print("number: ",n);
print(test(n));
n = 1234;
print("\nnumber: ",n);
print(test(n));
Related