Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First1 solution in Clear category for Binary Count by Krzysztof__wierblewski
def checkio(number):
strBinary = ""
pozostalo = number
wynik = 0
while pozostalo != 0:
if pozostalo == 1:
strBinary = strBinary + "1"
break
else:
temp = pozostalo % 2
strBinary = strBinary + str(temp)
pozostalo = pozostalo - (pozostalo/2)
pozostalo = int(pozostalo)
print(number)
print(strBinary)#dadwd
i = 0
while i < len(strBinary):
if strBinary[i] == "1":
wynik = wynik +1
i = i + 1
print(wynik)
return wynik
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(4) == 1
assert checkio(15) == 4
assert checkio(1) == 1
assert checkio(1022) == 9
Jan. 30, 2017