[Python] [Experiment 3] [demo display prime numbers, show all prime numbers within a range of two numbers]

Print all prime numbers between two integers:

(Using the square root should be stopped to determine whether to verify whether the value is a prime number)

for i in range(956253526252,9956253526252):
    k = 1
    if i == 2:
        print(i,"is a prime.")
        continue
    else :
        m = int(i ** 0.5)  #square root
        for j in range(2,m):
            if i%j == 0:
                k = 0;
                #print(i,"is not a prime.")
                break
    if k == 1:
        print(i," IS A Prime. " ) 
            
        
            
Print ( "   ..end ..   " ) 

# square root algorithm ** 0.5 will have two numbers, the square root of 4 is ± 2.

Output results are as follows:

 

 

 

-------- (I am dividing line) --------

reference:

None

 

Remarks:

Initial modified: September 22, 2019 18:11:00

Environment: Windows 7 / Python 3.7.2

 

Guess you like

Origin www.cnblogs.com/kaixin2018/p/11568535.html