Previous Post :
Python #19-Reversing of the given Number
Next Post :
Python #21-Regex in Python
Note Worthy: 0 and 1 are not prime numbers. The 2 is the only even prime number because all the other even numbers can be divided by 2.
Source Code:
number = int(input("Enter the number to check prime or not:"))
if number > 1:
for i in range(2, number):
if (number % i) == 0:
print number, "is not a prime number"
break
else:
print number, "is a prime number"
else:
print number, "is not a prime number"
Output:
Test case 1:
Enter a number : 10
10 is not a prime number
Test case 2:
Enter a number : 9
9 is a prime number
Python #19-Reversing of the given Number
Next Post :
Python #21-Regex in Python
What are prime number ?
Prime number are those when a number is divided by same number or then by 1 it should give you the remainder as Zero.
Eg: 2, 3, 5, 7, 11, 13, 17, 19
Note Worthy: 0 and 1 are not prime numbers. The 2 is the only even prime number because all the other even numbers can be divided by 2.
Source Code:
number = int(input("Enter the number to check prime or not:"))
if number > 1:
for i in range(2, number):
if (number % i) == 0:
print number, "is not a prime number"
break
else:
print number, "is a prime number"
else:
print number, "is not a prime number"
Output:
Test case 1:
Enter a number : 10
10 is not a prime number
Test case 2:
Enter a number : 9
9 is a prime number
Compile Your Code and Check Now..Hurry..!
Thanks and regards,
Tech bird
Comments