Jump to content

Can "for" loops have a stored value inside the range?


santiagoesc

Recommended Posts

Im trying to put a stored value inside the range of a "for" loop, and I don't know if that's permitted, an example would be:

M = np.array([[8,8,8,8],
                        [8,8,8,8],
                        [8,8,8,8],
                        [8,8,8,8]])

for j in range (4):
    for i in range(4):
        for k in range(2,M[i,j]):
            if M[i,j] % k == 0:
                print("yes")

            else

                print("no")
 

Link to comment
Share on other sites

I don't use Python much, but it looks like it should work just fine. The variable M is available and can be passed into the range() function, so there should be no problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...