初心者の python 愛好家として、これは非常に面倒です。
def isPrime(x):
if x < 0: raise Exception("The number is negative.")
if x == 0 or x == 1: return False
if x == 2: return True
else:
if x % 2 == 0: return False
for i in xrange (3, int(math.sqrt(x)), 2): #-------> This doesn't do anything.
if x % i == 0: return False # Even if I put 3 instead of i, it still prints numbers that are divisible by 3.
return True
for i in xrange (100):
if isPrime(i):
print i
9、15、21 などの数値を取得します。3 で割り切れるため、素数ではありません。私は何が欠けていますか?