Answer the question
In order to leave comments, you need to log in
Python3. Why doesn't the code work?
Hello!
There is a function:
def binary_symmetry(sieve):
a = []
for num in sieve:
x = format(num, 'b') # переводим num в двоичную систему
if len(x) % 2 == 0: # если длина двоичного числа - чётное число
half = (len(x) // 2) # то half равняется половине длины этого числа
one = ('1' * half)
zeroes = ('0' * half)
if len(x) == 2 and (x[0] == '1' and x[1] == '0'): # ВОТ ЭТО УСЛОВИЕ РАБОТАЕТ
a.append('{}:{}'.format(num, x))
elif x[0:half] == one and x[half:] == zeroes: # А ЭТО НЕ РАБОТАЕТ :(
a.append('{}:{}'.format(num, x))
return a
Answer the question
In order to leave comments, you need to log in
>>> int('10', 2)
2
>>> int('1100', 2)
12
>>> int('111000', 2)
56
>>> int('11110000', 2)
240
>>> int('1111100000', 2)
992
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question