if losttwice <= 2:
bet = _________ # <- Here
elif losttwice <= 5:
bet = bet * 2
else:
bet = startingbet
任何人都可以幫助我添加一件事嗎?我想在losttwice <= 2
(當我輸了1-2次)時得到50%的機率,因爲它是bet = startingbet
或bet = bet * 2
,有50%的機率。Python:隨機分配兩個值中的一個
if losttwice <= 2:
bet = _________ # <- Here
elif losttwice <= 5:
bet = bet * 2
else:
bet = startingbet
任何人都可以幫助我添加一件事嗎?我想在losttwice <= 2
(當我輸了1-2次)時得到50%的機率,因爲它是bet = startingbet
或bet = bet * 2
,有50%的機率。Python:隨機分配兩個值中的一個
if losttwice <= 2:
bet = random.choice((startingbet, bet*2))
if random.random() > 0.5:
(和頂部的import random
)可能會有用。你應該能夠根據它來弄清楚。
進口隨機
if losttwice <= 2:
if random.random() > 0.5:
bet = startingbet
else:
bet = bet * 2
elif losttwice <= 5:
bet = bet * 2
else:
bet = startingbet
if losttwice <= 2:
bet = random.choice([staringbet, bet*2])
elif losttwice <= 5:
bet = bet * 2
else:
bet = startingbet
Python有產生僞隨機性很大的模塊。文檔可以在here找到。如果您決定使用random.choice
,代碼將如下所示:
from random import choice
if losttwice <= 2:
bet = choice((startingbet, 2 * bet))
elif losttwice <= 5:
bet = bet * 2
else:
bet = startingbet