判斷某個數是不是素數
number = 12
i = 2
isPrime = True
while i < number:
if number % i == 0:
isPrime = False
break
i += 1
if isPrime:
print(number, "是素數")
else:
print(number, "不是素數")
輸出100以內的所有素數(素數就是隻能被1和本身整除的正整數)
number = 2
while number <= 100:
i = 2
isPrime = True
while i < number:
if number % i == 0:
isPrime = False
break
i += 1
if isPrime:
print(number)
number += 1