Created
October 19, 2021 20:48
-
-
Save cruepprich/75b57651ab650b76d368d6ba298a3c87 to your computer and use it in GitHub Desktop.
[Betting Game]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
wins=[] | |
losses=0 | |
nbr_games=5 | |
for gameidx in range(nbr_games): | |
wallet=maxwallet=100 | |
limit=200 | |
bet=1 | |
# print(f"\n\nNew game {gameidx}") | |
for betidx in range(100): | |
flip = random.randrange(0,2) | |
#0=loss, 1=win | |
if flip == 0: | |
wallet = wallet - bet | |
# print(f"Loss. Bet {bet*2}. Wallet {wallet}") | |
if wallet <= 0: | |
# print(f"Lost after {betidx} bets. Max {maxwallet}") | |
losses += 100 | |
break | |
bet = bet*2 | |
else: | |
maxwallet = max(wallet,wallet + bet) | |
wallet = wallet + bet | |
# print(f"Win {bet}. Wallet {wallet}") | |
if wallet >= limit: | |
# print(f"We won! {wallet}") | |
wins.append(wallet) | |
break | |
# print(f"Wallet final {wallet}. Max {maxwallet}") | |
print(f"Wins: {wins}") | |
maxwins = max(wins) | |
sumwins = sum(wins) | |
print(f"Max win: {maxwins}") | |
print(f"Sum win: {sumwins}") | |
print(f"losses: {losses}") | |
delta=sumwins-losses | |
print(f"Final outcome after {nbr_games} games: {delta}.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment