Sunday 12 February 2023

Prime number program in python

Prime number program in python

prime number is a number which is divisible by one and itself.

Program

def prime(n):
    if(n==0 or n==1):
        return 0
    elif(n==2):
        return 1
    else:
        for i in range(2,int(n**0.5)+1):
            if(n%i==0):
                return 0
        else:
            return 1
n=int(input())
if(prime(n)):
    print('{0} is a prime number'.format(n))
else:
    print('{0} is not a prime number'.format(n))
Output 1
150
150 is not a prime number
Output 2
5
5 is a prime number

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top