输入:
import mathfor n in range(2,10): for x in range(2,int(math.sqrt(n)+1)): if n % x == 0: print n, 'equals', x, '*', n/x break; else: print n,'is a prime number'
输出为:
"F:\Python\python.exe" -u "F:\pycode\prime number.py" 4 equals 2 * 25 is a prime number6 equals 2 * 37 is a prime number8 equals 2 * 49 is a prime number9 equals 3 * 3
为什么9会输出“9 is a prime number”