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% 的机会。
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% 的机会。
if random.random() > 0.5:
(import random
在顶部)可能有用。你应该能够根据它来计算它。
if losttwice <= 2:
bet = random.choice((startingbet, bet*2))
Python 有一个很棒的模块来生成伪随机性。文档可以在这里找到。如果您决定使用random.choice
,代码将如下所示:
from random import choice
if losttwice <= 2:
bet = choice((startingbet, 2 * bet))
elif losttwice <= 5:
bet = bet * 2
else:
bet = startingbet
随机导入
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