Is_Prime


#1

Hi Everyone,

My code (below) returns this error message:

Does your is prime function take exactly one argument (an integer)? Your code threw a "'int' object is not iterable" error._

Please help me...thanks...is it my indentation?

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

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



#2

You need to create a range like this:
for n in range(2, x):
cause you can't create a loop over an integer like x.
Try this code:
for n in 10:
print n

you'll see the same message.

PS: you have this in your code:
while n<x-1:
n = 2
n +=1

it's look like a potencial infinite loop


#3

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