DEV Community

Cover image for Day 2: Check Prime

Day 2: Check Prime

mattryanmtl profile image Matt Ryan ・1 min read

Python script to check if the input number is prime or not.

# take input from the user
num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
   # check for factors
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
       print(num,"is a prime number")

# if input number is less than
# or equal to 1, it is not prime
   print(num,"is not a prime number")
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app