samedi 4 février 2017

generate sum of results in python

We have a game, the game consists of 500 rounds. In each round, two coins are being rolled at the same time, if both coins have 'heads' then we win £1, if both have 'tails' then we lose £1 and if we have a situation where one coin shows 'heads' and the other coin shows 'tails' or vice versa then we just 'try again'.

coin_one = [random.randint(0, 1) for x in range(500)]
coin_two = [random.randint(0, 1) for x in range(500)]

game = zip(coin_one, coin_two)

for a, b in game:
    if a and b:
        print(1)
elif not a and not b:
        print(-1)
else:
    print('please try again') # or continue

The results of this are:

1 please try again -1 please try again please try again please try again -1 -1 1 -1 ,............, 1

I am trying to find the sum of the results so that I can know how much the player of the game won or lost after the game is complete (500 rounds).

After obtaining the result (total amount won) of playing just one game (500 rounds), I hope to play the game 100 times to create some summary statistics like mean, max, min and standard deviation of playing this game.




Aucun commentaire:

Enregistrer un commentaire