In the game of roulette there are many ways to bet, one of which is to bet on the red or black number. This is a simulation with probabilities a random number for said probability.
On my roulette table there are red, black and green colors, to each one assign the probability 0.45, 0.90, 1 respectively. if the random # falls in any of the probabilities. the amount wagered increases or decreases by 1.
the player starts with $ 50.
the game ends when the player adds $ 250.
my code is this:
from random import random
i=1
cantIni=50
cantFin=250
print("CANT INI\tALEAT\tG/P\tCANT FIN")
while cantIni <=cantFin:
aleatorio=random()
if aleatorio<0.45:
cantA=cantIni+1
print("{}\t\t{}\tGANA\t{}".format(cantIni,str(aleatorio)[0:4],cantA))
elif aleatorio<0.90:
cantA=cantIni-1
print("{}\t\t{}\tPIERDE\t{}".format(cantIni,str(aleatorio)[0:4],cantA))
else:
print("{}\t\t{}\t--\t{}".format(cantIni,str(aleatorio)[0:5],cantA))
cantIni+=1
print("---------------------------------FIN-DEL-PROGRAMA-------------------------------")
the output of the program looks like this:
CANT INI ALEAT G/P CANT FIN
50 0.72 PIERDE 49
51 0.12 GANA 52
52 0.41 GANA 53
53 0.61 PIERDE 52
54 0.30 GANA 55
55 0.95 -- 55
56 0.23 GANA 57
57 0.51 PIERDE 56
58 0.28 GANA 59
59 0.20 GANA 60
60 0.76 PIERDE 59
61 0.05 GANA 62
62 0.86 PIERDE 61
63 0.86 PIERDE 62
64 0.46 PIERDE 63
65 0.10 GANA 66
66 0.89 PIERDE 65
67 0.01 GANA 68
68 0.91 -- 68
69 0.40 GANA 70
70 0.68 PIERDE 69
71 0.45 PIERDE 70
72 0.23 GANA 73
73 0.71 PIERDE 72
74 0.88 PIERDE 73
75 0.26 GANA 76
- - - -
- - - -
- - - -
236 0.50 PIERDE 235
237 0.968 -- 235
238 0.34 GANA 239
239 0.51 PIERDE 238
240 0.46 PIERDE 239
241 0.967 -- 239
242 0.16 GANA 243
243 0.37 GANA 244
244 0.78 PIERDE 243
245 0.40 GANA 246
246 0.85 PIERDE 245
247 0.09 GANA 248
248 0.88 PIERDE 247
249 0.81 PIERDE 248
250 0.84 PIERDE 249
---------------------------------FIN-DEL-PROGRAMA-------------------------------
I have a mistake starting from the second iteration, since the initial quantity must be the final quantity of the previous one and so on until the final quantity of x itercion reaches 250, example:
CANT INI ALEAT G/P CANT FIN
50 0.72 PIERDE 49
51 0.12 GANA 52
for the second iteration, initial amount should be 49.
Agradesco the answers and comments.