Thursday, August 25, 2016

script to check prime number

import sys
num = int(sys.argv[1])

mulable = []
for i in range(1,num + 1,1):
    if num % i == 0:
        print i
        mulable.append(i)
       
if len(mulable) == 2:
    print str(num) + " is prime number"





- run

python script.py number

- ex
$ python check-prime-number.py 37
1
37
37 is prime number

$ python check-prime-number.py 8
1
2
4
8

No comments:

Post a Comment