Python Project: Is it a Prime
Python: Prime Number
Is it Prime
In a simple way, a Prime number is a number that cannot be made by multiplying other numbers. So 4 is Not Prime because we can say that 4 = 2 x 2, 6 is Not Prime because it can be produced by multiplying 3 x 2; but 5 Is Prime because we can’t find any integer numbers that can produce 5.
Numbers such as 1, 3, 5, 7, 11, 13 … all are Prime Numbers.
This function will ask the user to write a number then we will examine it to see whether it is a prime or not.
The Code:
num=int(input(“Enter a number: “))
def is_prime(num):
result=”Prime”
for t in range (2,num):
if num%t==0 :
result=”Not Prime”
break
return result
print num,’is’,is_prime(num)
Categories: Problem, Projects/Experiments, Python
ahradwani.com, Ali, Code, Computer, doha, Doha-Qatar, Language, Python
Comments (0)
Trackbacks (1)
Leave a comment
Trackback
-
April 16, 2019 at 5:50 amPython: Prime Numbers in Range | Ali's Photography Space...