def FindingTwoPrimes(n, p1, p2):
p1 = 0
p2 = 0
n = 0
primeList = []
for num in range(1,101):
if all(num%i!=0 for i in range(2,num)):
primeList.append(num)
print (primeList)
print ("Length of Primelist = ", len(primeList))
lengthOfPrimelist = len(primeList)
p1 = primeList[random.randint(0,lengthOfPrimelist)]
p2 = primeList[random.randint(0,lengthOfPrimelist)]
n = p1 * p2
print ("p1 =", p1)
print ("p2 =", p2)
return n
return p1
return p2
FindingTwoPrimes(n, p1, p2)
print(p1, p2, n)
所以上面是會發現,我將在公共密鑰加密系統的方法使用兩個素數的函數。但是,當我運行該函數時,它將p1,p2和n返回爲0.爲什麼是這樣以及如何解決它?此外,爲了使任何方法的代碼更有效的將:-)如何從函數中返回兩個值,這些值是在函數中創建的? - Python的
理解
使用'回報(N,P1,P2)',然後讓他們爲:'N,P1,P2 = FindingTwoPrimes(N,P1,P2)' –