2016-04-21
1-100素数判断pyhon程序

求取1-100的所有素数,采用函数式编程

1
2
3
4
5
6
7
8
9
def issu(x):
result=map(lambda y:x%y,range(2,x))
if len(result)!=0 and 0 not in result:
return 1
else:
return 0
print filter(issu,range(1,101))

答案为
[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]