I am trying to compile this piece of Python code-
def isPrime ( n ):
if n < 2 :
return false
for x in range(2,n):
if (n % x)==0:
return false
return true
def nthPrime ( n ):
y = 0
z = 1
while y< n:
z+=1
if isPrime( z ):
y+=1
return z
But I am having this error in line 9 on “def”
SyntaxError: invalid syntax
Here’s a fixed up version of your code, with proper indenting and using
TrueandFalse, nottrueandfalse:And here’s a version of your code that conforms more to the PEP 8 style guide for python:
I prefer the second piece of code.