def is_prime(n):
if n == 1:
return False
for i in range(2, n//2 + 1):
if n % i == 0:
return False
return True
print(filter(is_prime, range(1, 101)))
顺便给大家推荐一个python教程,写得很简洁
def is_prime(n):
if n == 1:
return False
for i in range(2, n//2 + 1):
if n % i == 0:
return False
return True
print(filter(is_prime, range(1, 101)))
顺便给大家推荐一个python教程,写得很简洁