Computer Science, asked by sahil9191, 1 year ago

✨✨question for CS student ✨✨


Write a Python function that takes a number as a parameter and check the number is prime or not. ​

Answers

Answered by rakeshchennupati143
2

Program:

def primecheck(num):

     for i in range(2,num):

           if num%i == 0:

                 return False;

                 break

     return True

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

if not primecheck(num):

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

else:

     print(num," is a prime number")

Output-1:

Enter a number : 97

97 is a prime number

Output-2:

Enter a number : 98

98 is not a prime number

Explanation:

  • i used normal prime number logic
  • if the if statement gets true inside the loop then the break breaks and returns False
  • and in prog i used if else to check if the returned is (not (true) ) or true
  • if true which means the it is a prime number
  • if ( not ( true ) )  which is false then that is not a prime number
  • if the if condition in the loop goes on failing then at last true is returns which means that is a prime number

----Hope you got what you wanted fro,if you liked it mark as brainliest,it would really help me.   :)

Answered by Anonymous
2

Answer:

def test_prime(n):

if (n==1):

return False

elif (n==2):

return True;

else:

for x in range(2,n):

if(n % x==0):

return False

return True

print(test_prime(9))

Similar questions