① 用python找质数
n=10000
numbers=list(range(2,n+1))
i=2
whilei<10001:
forminnumbers:
ifi<m:
whilem%i==0:#这边你为什么要用while呢,这边如果m=3,i=2的话是会进入死循环的,改成if语句试试
k=m#这个没必要存在,只接用numbers.remove(m)
numbers.remove(k)
i=i+1
print(numbers)
print(" Therewere",len(numbers),"primenumbersupto",n)
#下面是修改后的
n=10000
numbers=list(range(2,n+1))
i=2
whilei<10001:
forminnumbers:
ifi<mandm%i==0:
numbers.remove(m)
i=i+1
print(numbers)
print(" Therewere",len(numbers),"primenumbersupto",n)