program to check if a number is prime or not in python

Solutions on MaxInterview for program to check if a number is prime or not in python by the best coders in the world

showing results for - "program to check if a number is prime or not in python"
Bautista
21 Feb 2018
1# Program to check if a number is prime or not
2
3num = 29
4
5# To take input from the user
6#num = int(input("Enter a number: "))
7
8# define a flag variable
9flag = False
10
11# prime numbers are greater than 1
12if num > 1:
13    # check for factors
14    for i in range(2, num):
15        if (num % i) == 0:
16            # if factor is found, set flag to True
17            flag = True
18            # break out of loop
19            break
20
21# check if flag is True
22if flag:
23    print(num, "is not a prime number")
24else:
25    print(num, "is a prime number")
queries leading to this page
no is prime or not in pythonfind if a number is prime pythoncheck number is prime or not in pythonmodule to check if number is prime pythonpython prime number checkertest cases for function to check number is prime pythonhow to check whether a number is prime or not in pythonfind prime number is prime or not pythonhow to tell if number is prime pythonpython function check if prime numberpython code to check number of prime or notprime checker pythonhow to check if number is prime in pythoncheck prime pythonto check prime or not in pythonwap to read a number and check whether it is prime or not pythonpython check if its a primenumberpython prime testcompute if a number is prime pythonhow to check if a number is a prime number in pythonpython check if number is primewrite a python program to check whether a number is prime or not 3f 28use if 2c else conditional statement 29 python code to determines if x is prime or notpython prime check inbuiltwrite a python program to determine check it is prime number or not python check prime numberpython prime checkhow to check if a number is prime in python python to check whether a number is prime or not how to check if a number is prime or not in pythonfunction to check if it is a prime number pythoncompute if a number is prime python geekpython function to check if a number is primecheck the given number is prime or not in pythonfastest way to check if a number is prime pythonnumber is prime or not in pythontest for prime pythoncheck prime in pythonprimer number checker pythonhow to tell if a number is prime pythoncheck if prime pythonprime number or not in pythonprime check in pythonpython short check primeprime number check in pythoncheck prime number in pythonprime numbers or not python write a program to check if a given number is prime or not in pythonprogram to check if a number is prime in pythonpython code to see if a number is primepython function to check in number is primepython input number if prime number or notcheck if number is prime pythoncheck the number is prime or not in pythonfunction to check prime number in pythonhow to check if number is prime pythonpython program check prime number or notprogram to check if a number is prime or not in python