Computer Science, asked by renuga42, 11 months ago

write a programe to check whether a number is a prime r not in python​

Answers

Answered by Rapanzeel
3

See this example:

num = int(input("Enter a number: "))

if num > 1:

for i in range(2,num):

if (num % i) == 0:

print(num,"is not a prime number")

print(i,"times",num//i,"is",num)

break.

else:

Answered by AskewTronics
0

Below are the output and the program in python to check any number to be prime or not.

Output:

If the user input as 4, then it will prints not a prime number.

If the user inputs as 2, then it will prints the prime number.

Explanation:

number=int(input("Enter the number: "))#take a input from the user.

i=2

count=0

while(i<=(number/2)):#while loop which checks the number to be prime or not.

   if(number%i==0):

       count=1

       i=i+1

if(count==0):

   print("The number is a prime number")

else:

   print("The number is not a prime number")

Code Explanation :

  • The above code is in python language, which takes the inputs from the user and then runs the while loop up to the number divisible by 2.
  • Then checks the number to be divisible by all the value which is less than from that number.
  • If no number can divide that number, then it is a prime number.

Learn More:

Python : brainly.in/question/14689905

Similar questions