Is_prime


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/6?curriculum_id=4f89dab3d788890003000096#


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
        else:
            return True


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


#2

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


#3

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.


#4

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