Prime number program in python
prime number is a number which is divisible by one and itself.
Program
def prime(n):
if(n==0 or n==1):
return 0
elif(n==2):
return 1
else:
for i in range(2,int(n**0.5)+1):
if(n%i==0):
return 0
else:
return 1
n=int(input())
if(prime(n)):
print('{0} is a prime number'.format(n))
else:
print('{0} is not a prime number'.format(n))
Output 1
150 150 is not a prime numberOutput 2
5 5 is a prime number
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.