新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:如何用Python求素數(shù)之和
計算兩個正整數(shù)x,y(x<=y,包括x,y)素數(shù)和。首先通過isPrime函數(shù)來判斷一個數(shù)是否為素數(shù),再使用primeSum函數(shù)來返回素數(shù)和。

相關(guān)推薦:《python基礎(chǔ)教程》
以下為源碼:
def isPrime(n) : for i in range(2,n): if n % i == 0: return 0 break else: return n def primeSum(x,y): e = 0 for n in range(x,y): w = isPrime(n) e = w + e return e x,y =map(int, input().split()) print(primeSum(x,y))
程序截圖:
網(wǎng)站欄目:創(chuàng)新互聯(lián)Python教程:如何用Python求素數(shù)之和
新聞來源:http://m.fisionsoft.com.cn/article/dhecihs.html


咨詢
建站咨詢
