python program to find prime number n by seeing if they can divide evenly into prime numbers less that the squareroot of n
<p>How do I make this return the right results for primes less than 10 ?</p>

<pre><code>from math import *

def isPrime(n):

i = [c for c in range(int(sqrt(n)),0,-1) if c % 2 != 0 and c &gt; 1 ]

for x in i: 
    if n % x == 0:
        return print('%s is not prime' % (n))
return print('%s is prime number' %(n))


def main():

loopCnt = 'y'
while loopCnt != 'n':
    n = int(input('Enter a integer greater than 2: '))
    isPrime(n)


    loopCnt = input('Enter any key to try again or enter n to exit').strip().lower()


main()
</code></pre>

<p>It is not giving the desired output</p>

<p>Your error is that you exit the <code>for</code> loop in the first iteration <em>always</em>. You should only exit when you find it has a divisor, but otherwise you should keep looping. When you exit the loop without finding a divisor then is the time to return that fact.</p>

<p>So change:</p>

<pre><code>for x in i: 
    if n % x == 0:
        return print('%s is not prime' % (n))
    else:
        return print('%s is prime number' %(n))
</code></pre>

<p>to:</p>

<pre><code>for x in i: 
    if n % x == 0:
        return print('%s is not prime' % (n))
return print('%s is prime number' %(n))
</code></pre>

<p>Secondly, your <code>i</code> array includes the number 1, and since all numbers are dividable by 1 that does not make sense. So the range should stop before 1 instead of 0. Also, you should include 2 as a divider.</p>

<p>So change:</p>

<pre><code>i = [c for c in range(int(math.sqrt(n)),0,-1) if c % 2 != 0]
</code></pre>

<p>By:</p>

<pre><code>i = [c for c in range(int(math.sqrt(n)),1,-1) if c % 2 != 0] + [2]
</code></pre>

<p>See it in <a href="https://repl.it/DxN2/1" rel="nofollow">repl.it</a></p>

python