Q. Write a Python function that takes a number as a parameter and checks whether the number is prime or not.

 

Answer =


def prime(a):
    for i in range (2,a) :
        if a % i == 0 :
            return "This is not prime number"
    return "Prime number"

a = int(input("Enter a number : "))
print(prime(a))

 

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. there should be an 'else' statement... please revise this code...

    ReplyDelete
    Replies
    1. No, here return statement will work as else statement.

      Delete
  2. Where is the output

    ReplyDelete
  3. Thank you for correct and use able code.

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post