Check Prime number by python by R4R Team

what is prime number ??

- A number which is divisible by 1 and itself only is called prime number.
example - 11,17,13,3 etc.

non-prime- 4,8,9,12,34,100 etc.

program -

n=int(input())
prime=1
for i in range(2,int(n-1)):
if n%i==0:
prime=0
break
if prime==1:
print("Number is prime")
else:
print("Number is not prime")


output -

4
Number is not prime
11
Number is prime


In this program, we take input of number from the user and check number is prime or not, we start loop from 2 until the n-1, where n is a input number. then in if condition we check if number is divisible from any other number then it is prime so we break loop. and at last we check that our prime variable is changed or not, if not changed then it is prime number other not prime.
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!