Wednesday, August 12, 2015

How to find out prime number in python

__author__ = 'Polo-Dev'
def is_prime(num):
    check = True
    if num > 1:
       if num > 2:
           for i in range(2, int(num/2)+2):
               if num % i == 0:
                   check = False
                   break
    else:
        check = False

    return check

number = 100
for i in range(1, number+1):
    if is_prime(i):
        print(i)

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }