有人可以解釋這個程序和輸出嗎?我對if語句表示懷疑。我無法理解break語句在此是如何工作的:程序如何控制break語句
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print n, 'equals', x, '*', n/x
break
else:
# loop fell through without finding a factor
print n, 'is a prime number'
輸出:
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
請格式化代碼和輸出。併發布真正的代碼沒有.... – 2013-05-08 22:55:13