Computer Science, asked by BuntyBanna, 1 year ago

Python program for checking prime number

Answers

Answered by azax25547
2
# Python program to check if the input number is prime or not

num = 407

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

# prime numbers are greater than 1
if num > 1:
# check for factors
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:
print(num,"is a prime number")

# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")
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