Python program to determine if a given number is prime number

What are prime numbers?

Those numbers which have only two factors, one and the number itself are called prime numbers and the numbers with more than two factors are called composite numbers.

Example of prime number:- 2,3,5,7,11,13....


Algorithm :-

Step 1- Start
Step 2- Input the number
Step 3- Declare variable i
Step 4- Initialize variable 
             i2
Step 5- if i<number 
                go to Step 6
             else 
                go to Step 7
Step 6- if number%i==0 
                number is not prime 
                go to Step 8
             else i=i+1 
                go to Step 5
Step 7- number is prime
Step 8- Display output
Step 9- Stop

Flowchart :-



Code :-


number=int(input("Enter a number:"))
for i in range(2,number):
    if number%i==0:
        print("not a prime number")
        break
else:
    print("prime number")


Comments

Popular posts from this blog

Python program to print factorial of a given number

Python program to determine if a given number is odd or even