第1步
for n in range(2, 6):#n=2
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第2步
for n in range(2, 6):#n=2
for x in range(2, n):#循环结束
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第3步
for n in range(2, 6):#n=2
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第4步
for n in range(2, 6):#n=2
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
输出:2 is a prime number
第5步
for n in range(2, 6):#n=3
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第6步
for n in range(2, 6):#n=3
for x in range(2, n):#x=2
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第7步
for n in range(2, 6):#n=3
for x in range(2, n):#x=2
if n % x == 0:#3%2=1,False
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第8步
for n in range(2, 6):#n=3
for x in range(2, n):#循环结束
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第9步
for n in range(2, 6):#n=3
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第10步
for n in range(2, 6):#n=3
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
输出:3 is a prime number
第11步
for n in range(2, 6):#n=4
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第12步
for n in range(2, 6):#n=4
for x in range(2, n):#x=2
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第13步
for n in range(2, 6):#n=4
for x in range(2, n):#x=2
if n % x == 0:#4%2=0 ,True
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第14步
for n in range(2, 6):#n=4
for x in range(2, n):#x=2
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
输出:4 equals 2 * 2
第15步
for n in range(2, 6):#n=4
for x in range(2, n):#x=2
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第16步
for n in range(2, 6):#n=5
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第17步
for n in range(2, 6):#n=5
for x in range(2, n):#x按顺序取值2,3,4
if n % x == 0:#if条件都判断False
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
第18步
for n in range(2, 6):#n=5
for x in range(2, n):#x按顺序取值2,3,4,下一步if条件都判断False
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')
输出:5 is a prime number