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 bodyCodePudding user response: