美文网首页
Python Day1

Python Day1

作者: Hermosa_SU | 来源:发表于2016-05-29 00:25 被阅读0次

    愚蠢的求素数

    import math
    import time
    
    def BySqrt(a,b):
        numList = list()
        flag = 0
        for i in range(a,b):
            for j in range(2, int(math.sqrt(i)) + 1):
                if i % j == 0:
                    flag = 1
                    break
                else:
                    flag = 0
            if flag == 0:
                numList.append(i)
        return numList
    
    for num in BySqrt(1,100):
        print num
    
    start = time.clock()
    end = time.clock()
    print end-start
    

    求和

    def AddUp(a,b):
        s = 0
        for i in range(a,b):
            s=s+i
        return s
    
    print AddUp(1,100)
    

    相关文章

      网友评论

          本文标题:Python Day1

          本文链接:https://www.haomeiwen.com/subject/utqqdttx.html