N is a prime number?

 Programe PYTHON checks if the number N is a prime number. 
The algorithm consists of dividing the number N by all successive numbers 1, 2, 3,, sqrt (N) as long as the rest of the divisions are nonzero.
The PYTHON program is:

# Checks if the number N is a prime number
N = int(input('Number is:'))
# A = sqrt(N)
A = N**0.5
B = int(A)
C = False
D = 2
while (C == False) and (D <= B):
    if(N % D) == 0:
        C = True
    D = D + 1
if (C == False):
    print ('Number', N,  'prime')
else:
    print ('Number', N,  'is not prime')


The results of the program are:

Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.

================ RESTART: /Users/ionivan/Documents/NumarPrim.py ================
Number is:887
Number 887 prime

Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.

================ RESTART: /Users/ionivan/Documents/NumarPrim.py ================
Number is:1000
Number 1000 is not prime





(March 22, 2022)

Comments

Popular posts from this blog

Pointers in PYTHON?

Generates M prime numbers