Https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/isprime

I keep getting a syntax error for the following code and I’m having trouble understanding why. The syntax error is from the "if x % n == 0 line.

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

print is_prime(4)
print is_prime(5)

2 Likes

Hi!

The clue is in the syntax for if-statements. I always google documentation if I’m in doubt. Here’s a helpful link https://docs.python.org/3/tutorial/controlflow.html

This example is short, but in future times, especially for syntax, be sure to format the code with the </> button :slight_smile:

@code3705652457 and welcome to the forums :tada: :tada:

2 Likes