Oops, try again. Does your is_prime function take exactly one argument (an integer)? Your code threw a "'int' object is not iterable" error.

def is_prime (x):
    for n in x:
        n <= (x-1) 
        n >= 2
        if x % n == 0:
            return False
            return True

Why does this code not work?Can someone explain it?


int are not iterable meaning that you can't parse through them using a for loop or other such things.


For your problem, what do you get if you print the n after the for loop?
You'd find that the output wont print at all. In this case, x is an integer, not a list.
There is nothing the repeat in just a number, so you will have to change the x into something that will iterate.
for n in x: is the problem for your error.


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