0

I try to check the several modules of a numbers based on values of an array.

 array = [1,2,3,4,5]
 number = 10

now I want to do automate the following:

if 10%1 ==0:
    if 10%2 == 0:
        if 10%3 == 0:
            if 10%4 == 0:
                if 10%5 ==0:
                     print "10 is dividable by all numbers in the array"

I want to make the number of nested if statements based on the length of the array and get the number to check if 10 is dividable out of the array. Is there a way to do this with for loops?

Thanks.

1

1 Answer 1

3

Use all:

array = [1,2,3,4,5]
number = 10
if all(number % x == 0 for x in array):
    print "%s is dividable by %s" % (str(number), str(array))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.