Python program to check whether a number is Prime or not
In this article, you will learn to find whether the number is a prime number or not.
What is a Prime number?
Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # prime number in python # first we will take input from the user to check is prime number or not num = int(input("Enter number to check: ")) # Prime number is always greater than 1 if num > 1: # now divide the number by 2 to number itself for i in range(2, int(num/2)+1): # And check the reminder is zero if (num % i) == 0: # if reminder is zero than the number is not a prime number print(num, "is not a prime number") break else: print(num, "is a prime number") else: print(num, "is not a prime number") # prime number in python - docodehere.com |