0
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% 的机会。

4

5 回答 5

2

if random.random() > 0.5:import random在顶部)可能有用。你应该能够根据它来计算它。

于 2013-07-03T23:47:41.640 回答
2
if losttwice <= 2:
    bet = random.choice((startingbet, bet*2))
于 2013-07-03T23:49:01.823 回答
1

Python 有一个很棒的模块来生成伪随机性。文档可以在这里找到。如果您决定使用random.choice,代码将如下所示:

from random import choice
if losttwice <= 2:
    bet = choice((startingbet, 2 * bet))
elif losttwice <= 5:
    bet = bet * 2
else:
    bet = startingbet
于 2013-07-03T23:50:33.880 回答
0

随机导入

if losttwice <= 2:
        if random.random() > 0.5:
            bet = startingbet
        else:
            bet = bet * 2
elif losttwice <= 5:
    bet = bet * 2
else:
    bet = startingbet
于 2013-07-03T23:50:01.853 回答
0
if losttwice <= 2:      
    bet = random.choice([staringbet, bet*2])
elif losttwice <= 5:
    bet = bet * 2
else:
  bet = startingbet
于 2013-07-03T23:50:15.253 回答