0

number of ones

maybe it help you friend

16th Jul 2022, 11:54 AM
wqd dqwwdqwd
wqd dqwwdqwd - avatar
5 Respuestas
+ 1
decimal_number = int(input()) binary_number = bin(decimal_number) kick_prefix = binary_number[2:] build_list = list(kick_prefix) a = 0 for i in build_list: if i == '1': a += 1 else: continue print(a)
16th Jul 2022, 11:55 AM
wqd dqwwdqwd
wqd dqwwdqwd - avatar
+ 1
a=kick_prefix.count("1")
16th Jul 2022, 12:56 PM
Oma Falk
Oma Falk - avatar
0
x = int(input()) y='' while True: y += str(x % 2) x = x // 2 if x // 2 == 0: break y= y+ '1' print(y.count('1'))
11th Sep 2023, 2:11 PM
Denis
Denis - avatar
0
print(str(bin(int(input()))).count('1')) The long version: decimal_number = int(input()) binary_number = bin(decimal_number) binary_string = str(binary_number) number_of_ones = binary_string.count('1') print(number_of_ones) Explanation: -Turn the given integer into a binary number. E.g. 24 -> 11000 -Turn the binary number into a string. E.g. 11000 -> "11000" -Use the .count() function to count how many times the "1" character appears in the string
29th Sep 2023, 3:33 PM
Syed Rafiq Kazim
0
num = format(int(input()), "b") it = list(num) count = 0 for let in it: if let == "1": count += 1 print(count)
2nd Jul 2024, 6:22 AM
Solomon Adenuga