python编码-100内及100素数

2018-03-20  本文已影响0人  Cookie_hunter

1.

import math
a =[]
def num(max):
    i = 2
    for  i in range (2,max):
        j = 2
        for j in range (2,int(math.sqrt(i))+1):
            if (i % j == 0):
                break
        else:
            a.append(i)


num(100)
print(a)

2.

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
num=[];
i=2
for i in range(2,101):
   j=2
   for j in range(2,i):
      if(i%j==0):
         break
   else:
      num.append(i)
print(num)

3.

import math
def func_get_prime(n):
  return filter(lambda x: not [x%i for i in range(2, int(math.sqrt(x))+1) if x%i ==0], range(2,n+1))
 
print func_get_prime(100)
上一篇下一篇

猜你喜欢

热点阅读