js和python获取1-100之间的质数

js

for (let i = 2; i <= 100; i++) {
  let iszs = true
  for (let j = 2; j < i; j++) {
    if (i % j === 0) {
      iszs = false
      break
    }
  }
  if (iszs) {
    zs.push(i)
  }
}
console.log(zs)

python

zs = []
for i in range(2, 101):
  iszs = True
  for j in range(2, i):
    if(i % j == 0):
      iszs = False
      break
  if(iszs):
    zs.append(i)
print(zs)

 

posted @ 2023-11-29 15:26  herry菌  阅读(41)  评论(0编辑  收藏  举报