# Prime numbers with a while and a function

Hey!

I have done a check of prime numbers with a while:

``````num = int(raw_input("Dame u numero \n"))
creo_que_es_primo = True
divisor = 2
while divisor < num:
if num % divisor == 0:
creo_que_es_primo = False
break
divisor += 1

if creo_que_es_primo == True:
print "El nomero,", num, "Es  primo"
print divisor
else:
print "El numero", num, "No es primo"
print divisor
``````

But now i want to do this with a function def,:

``````creo_primo = True
divisor = 2

def isPrime(n):
while divisor < n:
if (n % divisor) == 0:
creo_primo = False
break
divisor += 1
return creo_primo

# Tests....
print isPrime(3) # Should output True
print isPrime(143) # Should output False
print isPrime(790003) # Should output True

``````

And i got this error:

But if i have this in the correct block!!

the indention seems to be poorly done by your editor, i re-indented the code:

``````def isPrime(n):
creo_primo = True
divisor = 2
while divisor < n:
if n % divisor == 0:
creo_primo = False
break
divisor += 1
return creo_primo

# Tests....
print isPrime(3) # Should output True
print isPrime(143) # Should output False
print isPrime(790003) # Should output True

``````

and now everything is fine

1 Like

Thanks very much!!
I have done this post because i didnt know exactly what was the problem, altough i have tried to use the â€śUn - comment regionâ€ť of my editor for solve thisâ€¦

i have no idea what caused it, i have set my `vim` (a command line text-editor) to work wonderfully well for python, so i used vim to re-indent the code, and then everything was good

Aww I use Komodo IDE OSX, and i am very happy with this, so i will forget this mistakeâ€¦
likewise thanks!!