Sunday 6 April 2014

How to check prime number in using Python.

#!/usr/local/bin/python2.7
# pleases follow the indention as it is most important in python. python don't use begin/end, if/end if or loop/
#end loop so python identify statement by indention.

def PrimeNumber(n):
  if n==1 or n==2:
    return 0
  for i in range(3,n/2+1):
    if n%i == 0:
      return 0
  return 1

n = input ('Enter the number to check prime: ')
if PrimeNumber(n)==1:
  print('\n%d is Prime Number'%n)
else:
  print('\n%d is not Prime Number'%n)

No comments: