# How to print prime numbers in python?

Prime numbers are those which is divisible by the number itself and one.

Here we’ll see a code here by which we can check whether a number is prime or not.

e.g.,

n = int(input("Enter a number: ")) if n > 1: for i in range(2,n): if (n % i) == 0: print(n,"is not a prime number") print(i,"times",num//i,"is", n) break else: print(n,"is a prime number") else: print(n,"is not a prime number")

e.g.,

l = 20 u = 40 for n in range(l, u + 1): if n > 1: for i in range(2, n): if (n % i) == 0: break else: print(n)

In this way we can print prime numbers in python.

Subscribe

Login

Please login to comment

0 Discussion