2015-01-08 50 views
0

我想編寫一個簡單的鞅系統來計算在輪盤上x旋轉後「我的」賬戶中將有多少錢。該計劃很簡單,只是爲了實驗。到目前爲止,我有這個,但是,我想補充一點,如果這個隨機數字a是例如兩倍或更多......與d相同,我會加倍我的賭注。所以,如果一個.. = 2,A = 5我敢打賭兩個等8,16,32 4而不是..計算資金鞅系統

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

保持一個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,並在else子句中用bet = original_bet進行重置。