Python Program to Check Prime Number
www.programiz.com › examples › prime-number# Program to check if a number is prime or not num = 29 # To take input from the user #num = int(input("Enter a number: ")) # define a flag variable flag = False # prime numbers are greater than 1 if num > 1: # check for factors for i in range(2, num): if (num % i) == 0: # if factor is found, set flag to True flag = True # break out of loop break # check if flag is True if flag: print(num, "is not a prime number") else: print(num, "is a prime number")
Python program to check if a number is Prime or not
www.tutorialspoint.com › python-program-to-checkFeb 19, 2019 · Python program to check if a number is Prime or not. Python Server Side Programming Programming. In this, we’ll write a program that will test if the given number which is greater than 1 is prime or not. A prime number is a positive integer greater than 1 and which has only two factors 1 & the number itself for example number: 2, 3, 5, 7… etc are prime numbers as they have only two factors .i.e. 1 & the number itself.