Python: Prime Number

This Python script will generate a list of prime number.

def isPrime(x):
    for i in range(2, x):
        if x%i == 0:
            return false
        return true

for c in range(1,10):
    if isPrime(c):
        print c,

output:

>>> 1 2 3 5 7

Related

This entry was posted in Python and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>