------------------------------------------------------------------------------------------------------------------------------------------------------------------
n = 2 :
x = 2
while x < n : # 2 < 2 条件不成立,无法进入循环,直接来到 else
else :
print(2 , "是一个素数")
------------------------------------------------------------------------------------------------------------------------------------------------------------------
n = 3
x = 2
while x < n : # 2 < 3 条件成立,进入循环
if n % x == 0 : # 3 % 2 = 1 条件不成立
x += 1
x = 3
while x < n : # 3 < 3 条件不成立,无法进入循环,直接来到 else
else :
print(3 , "是一个素数")
------------------------------------------------------------------------------------------------------------------------------------------------------------------
n = 4
x = 2
while x < n : # 2 < 4 条件成立,进入循环
if n % x == 0 : # 4 % 2 = 0 条件成立
print(4,"=",2,"*",4//2)
break # 结束循环
------------------------------------------------------------------------------------------------------------------------------------------------------------------
n = 5
x = 2
while x < n : # 2 < 5 条件成立,进入循环
if n % x == 0 : # 5 % 2 = 1 条件不成立
x += 1
x = 3
while x < n : # 3 < 5 条件成立,进入循环
if n % x == 0 : # 5 % 3 = 2 条件不成立
x += 1
x = 4
while x < n : # 4 < 5 条件成立,进入循环
if n % x == 0 : # 5 % 4 = 1 条件不成立
x += 1
x = 5
while x < n : # 5 < 5 条件不成立,无法进入循环,直接来到 else
else :
print(5 , "是一个素数")
n = 6
x = 2
while x < n : # 2 < 6 条件成立,进入循环
if n % x == 0 : # 6 % 2 = 0 条件成立
print(6,"=",2,"*",6//2)
break # 结束循环
------------------------------------------------------------------------------------------------------------------------------------------------------------------
|