1. 程式人生 > 其它 >浙大版《Python 程式設計》題目集 第6章函式-2 使用函式求素數和

浙大版《Python 程式設計》題目集 第6章函式-2 使用函式求素數和

技術標籤:# Python學習筆記python

第6章函式-2 使用函式求素數和

import math
def prime(p):
    if p == 1:
        return False
    for i in range(2, int(math.sqrt(p) + 1)):
        if p % i == 0:
            return False
    return True
def PrimeSum(m,n):
    res = 0
    for i in range(m, n + 1):
        if prime(i):
            res +=
i return res