6. is_prime


#1



Can anyone help me look at my code? It's not working. Thank you!!!


def is_prime(x):
    listnumber=[]
    n=x
    while n>2:
        n=n-1
        listnumber.append(n)
    return listnumber
    for i in listnumber:
        if x%i ==0:
           return False
        else:
            return True            
print is_prime(10)


#2

Question: Why are you trying to use an array?


#3

for example for number 10
I was trying to make a list [9,8,7,6,5,4,3,2]
then divide 10 by each number from the list in the loop and see if it is prime number


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.