How to check the prime number 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")

This is how we can check whether a number is a prime number or not.
Subscribe
Login
Please login to comment
0 Discussion