Home > other >  Bosses, could you tell me how to judge this program is the prime number 2?
Bosses, could you tell me how to judge this program is the prime number 2?

Time:09-23

"" "
Enter a positive integer to judge if it is prime

Version: 0.1
Author: LuoHao
Date: 2018-03-01
"" "
The from math import SQRT

Num=int (input (' please enter a positive integer: '))
End=int (SQRT (num))
Is_prime=True
For x in range (2, end + 1) :
If num % x==0:
Is_prime=False
Break
If is_prime and num!=1:
Print (' % d is a prime number '% num)
The else:
Print (' % d is not a prime num %)

Judgment integer 2, in the loop, x 2 for assignment, num % x==0, then is_prime not directly output is False, the judgment is not a prime number 2?

CodePudding user response:

Judgment is num, not x, num is 2, 3, the end is 1, then the for do not execute the loop body

CodePudding user response:

reference 1st floor chuifengde response:
judgment is num, not x, num is 2, 3, the end is 1, then the for do not execute the loop body.


But the end is 1, the end is + 1==2
For x in range (2, 2) :
It will not perform the if in the loop?

CodePudding user response:

The scope of the range (s, e) is [s, e)