此代碼是針對最大成對產品的,我一直在測試它,但我遇到了一些問題。爲什麼我的隨機列表中的值總是相同的?
import sys
import random
while True:
a=int(random.randrange(1,1000000,101))
keys =[] # keys is empety list
i=0
while i < a :
keys.append(int(random.randrange(1,10000,8)))
i=i+1
keys.sort()
print(keys[-1], keys[-2])
x=keys[-1]*keys[-2]
print("the max is ",x)
但是,由於某些原因,代碼的輸出總是相同的。
9993 9993
the max is 99860049
9993 9993
the max is 99860049
9993 9993
the max is 99860049
9993 9993
the max is 99860049
我不明白爲什麼會發生這種情況,一個解釋將不勝感激。
EUH的'keys'是相同的,以及... –