Check if number is prime
This is very simple.
I have written a simple Python code to solve the problem. I have also attached the output in Step 2.
----------------------------------------------- Python Code -------------------------------------------------
def prime(n):
if n > 1:
for i in range(2, n):
if (n % i) == 0:
print(n,"is not a prime number ")
break
else:
print(n,"is a prime number ")
return
def check(n):
if n < 0:
print(" Please enter a positive number ")
n = int(input(" Now enter a positive number (NOT 0) : "))
prime(n)
else:
prime(n)
if __name__ = "__main__":
N = int(input(" Enter a number : "))
print(check(N))
Step by step
Solved in 2 steps with 2 images