我想写一个简单的鞅系统来计算在轮盘赌上的x旋之后,“我的”帐户里有多少钱。这个程序很简单,只是为了实验。到目前为止,我有这个,但是,我想补充一下,如果这个随机数a是两倍或更多.就像我会加倍打赌一样。所以如果..。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,"€")发布于 2015-01-09 02:47:18
保留一个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重置。
https://stackoverflow.com/questions/27850744
复制相似问题