Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Binary Count by zgub4
def checkio(number):
bin_str = decimal_to_binary_string(number)
counter = 0
for i in bin_str:
if i == "1":
counter += 1
return counter
def decimal_to_binary_string(number):
binary_string = ""
while number != 0:
if number % 2 == 0:
binary_string = "0" + binary_string
else:
binary_string = "1" + binary_string
number = number // 2
return binary_string
if __name__ == '__main__':
assert checkio(4) == 1
assert checkio(15) == 4
assert checkio(1) == 1
assert checkio(1022) == 9
Oct. 22, 2017