Getting NameError even though variable is defined

  python, python-3.x

I’m trying to find all the numbers that divide all the element of b evenly.

This is my code:

a = [2, 4]
b = [16, 32, 96]
maxOfb = max(b)
factorOfb = []
for i in range(1, int(maxOfb/2)):
    if all(j % i == 0 for j in b):
        factorOfb.append(j)
print(factorOfb)

when I’m executing it, it’s giving this error:

NameError: name 'j' is not defined

Source: Python-3x Questions

LEAVE A COMMENT