program for whether the no.is prime or not.In Python
Answers
Python Program to Check if a Number is a Prime Number
a=int(input("Enter number: "))
k=0
for i in range(2,a//2+1):
if(a%i==0):
k=k+1
if(k<=0):
print("Number is prime")
else:
print("Number isn't prime")
>>Runtime Test Cases
Case 1:
Enter number: 7
Number is prime
Case 2:
Enter number: 35
Number isn't prime
Python Program :
Explanation:
number=int(input("Enter the number to check prime number: "))#Take the number from the user.
c=0
for i in range(2,int((number/2)+1),1):#For loop which check the number to be prime.
if(number%i==0):#if condition check the number is divisble or not.
c=2
break
if(c==0):
print("The number is prime number")#Print for prime number.
else:
print("The number is not prime number")#Print for not a prime number.
Output :
- If the user input as 2, then it will print "prime number".
- If the user input as 4, then it will print " not a prime number".
Code Explanation :
- The above code is in Python language, in which the first line of the program is used to instruct the user and then take the input from the user.
- Then the for loop runs from 2 to number/2 to check the number divisible by any number or not.
- If the number id divisible then print it is a prime number otherwise print the number is not a prime number.
Learn More :
- Python : https://brainly.in/question/14689905