计算资金鞅系统

2024-06-16 10:34:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我想写一个简单的鞅系统来计算有多少钱将在“我的”帐户后在轮盘赌x旋转。程序简单,仅用于实验。到目前为止,我有这个,但是我想补充一下,如果这个随机数a是两倍或更多。。。和d一样我会加倍打赌。所以如果。。a=2和a=5我赌4而不是2,以此类推8,16,32。。在

from random import*
money = 100
bet = 2
d = [0, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35]
for i in range(100):
    a = randint(1, 36)
    if a in d:
        money -= bet
    else:
        money += bet
print("Your money",money,"€")

Tags: infromimport程序forif系统range
1条回答
网友
1楼 · 发布于 2024-06-16 10:34:57

保留一个repeat变量,并使用该变量查看是否连续得到a in d。在

from random import randint # Bad practice to import *

money = 100
bet = 2

# Consider revising the below to sets, which are faster for membership tests
d = [0, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35]

repeat = False

for _ in range(100):  # You never use the loop variable, so denote that by naming it _
    a = randint(1, 36) # btw, you have 0 in d but your randint starts from 1...

    if a in d:
        money -= bet
        if repeat:
            bet *= 2
        repeat = True
    else:
        money += bet
        repeat = False

print("Your money",money,"€")

您没有指定下注失败时下注值的变化。如果你连续赢了一个赌注,上面的方法只是继续增加赌注。当你输了,赌注不会下降。在

如果要重置bet值,只需将该数据存储在一个单独的变量中,如original_bet,并在else子句中用bet = original_bet重置。在

相关问题 更多 >