Write a code using a function to check whether a given number is prime number or not

Advertisements
Advertisements
Advertisements3
Advertisements4
Advertisements6
Advertisements66
#Write a code using a function to check whether a given number is prime number or not
x= int(input("enter a number: "))
def primeornot(x):
    if x <= 1:
        print("1 is not a prime number ")
    elif x == 2:
        print("2 is a prime number")
    elif x == 3:
        print("3 is a prime number")
    else :
        if x%2 == 0 or x%3 == 0 or x%5 == 0 or x%6 == 0 :
                print("Given number is not a prime number")
        else :
                print(" Given number is a prime number")
primeornot(x)



Author: Lakshmi Prasanna Ponnala

Completed M.Tech in Digital Electronics and Communication Systems.

Leave a Reply

error: Content is protected !!

Discover more from ece4uplp

Subscribe now to keep reading and get access to the full archive.

Continue reading