104k views
5 votes
From a comma-separated list of binary numbers, find how many numbers are divisible by a given number x. x is an integer in the range 1 to 9 and the total count of the binary numbers in the list will be less than 1000. You're allowed to create new functions.

User ZhengCheng
by
5.3k points

1 Answer

6 votes

In python:

lst = ([your binary numbers go here])

x = your integer goes here

lst1 = ([])

for i in lst:

lst1.append(int(i, 2))

print(lst1)

total = 0

for w in lst1:

if w % x == 0:

total += 1

print(f"There are a total of {total} number(s) divisible by {x}")

I hope this helps!

User Vadim  Kharitonov
by
6.1k points