Question Write a Python program to check if the number is prime or not?
Answer: Example to check whether an integer is a prime number or not.
1 2 3 4 5 6 7 8 9 | n= int(input( "enter the number that has to be checked:")) a=0 for i in range(2,int((n/2))): if(n%i ==0): //finding whether the number has a factor or not a=a+1 if(a>1): print("it is not prime number.") else: print("it is prime number.") |
Output
1 2 3 4 5 | enter the number that has to be checked:97 it is prime number. enter the number that has to be checked: 54 it is not prime number. |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.