# Is_prime - don't understand the error

#1

I’m not sure what’s wrong with my code. Error says:

File “python”, line 4
if x % n = 0:
^
SyntaxError: invalid syntax

``````

def is_prime(x):
nums = [2,1,0,x-1]
for n in nums:
if x % n = 0:
return False
else:
return True

``````

#2

a single equal sign means assign, why would you do this in a if condition?

#3

oh god… I didn’t notice that till now… thanks
concentration problems

#4

now I have other error:
Your function fails on is_prime(1). It returns True when it should return False.

#5

i know, i gave you the change to discover first more yourself.

lets see:

``````def is_prime(x):
nums = [2,1,0,x-1]
for n in nums:
if x % n == 0:
return False
else:
return True
print is_prime(9)
``````

i don’t see how your function would determine if 9 is a prime number

your function should work for any number supplied as argument on function call (from -9999 till +9999)

i don’t see how your function would do this? There seems to be only a list with 4 numbers. For `x=9` we need to test if `9` is divisible by 2, 3, 4, 5, 6, 7 and 8

#6

I solved it. Thanks for help!

#7