计算资金鞅系统

时间:2015-01-08 22:33:06

标签: python

我想写一个简单的鞅系统来计算将会有多少钱?" my"在轮盘赌上旋转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,"€")

1 个答案:

答案 0 :(得分:1)

保留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,"€")

当您输掉赌注时,您未指定下注值会发生什么变化。如果你连续赢了赌注,上面只会继续加注赌注。当你输了时,赌注值不会下降。

如果您想重置投注值,您只需将该数据存储在单独的变量original_bet中,并在bet = original_bet子句中使用else重置。