Print prime numbers up to N and Check N is prime or not using Python Programming Language

 Print prime numbers up to N and Check N is prime or not using Python Programming Language.

 

Answer )

Only the number divided by itself and divided by  1 is called as Prime Number.

Below code is for check prime for number and also print prime numbers for up to that range(N).

Below code is only on python language.

If it is helpful for you , then comment below .

 

def checkPrime(n):
    if(n==0 or n==1 or n<0):
        return False
    for i in range(2,n):
        if(n%i==0):
            return False
    return True
 
n = int(input("Enter Numer : "))
if(checkPrime(n)):
    print(n," is Prime Number")
else:
    print(n," is Not Prime Number")

print("\nPrime Numbers up to ",n," : " ,end=" ")
for i in range(1,n+1):
    if(checkPrime(i)):
        print(i,end=" ")


Picture view:

 

Output Picture view:


Comments

Popular posts from this blog

Print prime numbers up to N and Check N is prime or not using Java Programming Language

javascript arrow function