Question: I have code that does nested for loops of dice rolling, with the results related to betting. 2 dice are rolled 10 times and this simulation is then repeated 100 times. I am trying to plot the results of each simulation where each line would be the change in $ balance from 0-10 rolls. currently the graph gets created but nothing is shown on it
Repl link: https://replit.com/@kadam12/Dice-Rolling-Repetition
#dice game: rolling 2 die 100 times, hoping for doubles which give 4x payout
#import time
#required packages:
#for graphing?
import matplotlib.pyplot as plt
#for random number generation
import random
#die rolling function
def roll_dice():
die_1 = random.randint(1,6)
die_2 = random.randint(1,6)
#same number check
if die_1 == die_2:
same_num = True
print(f"dice are same value of {die_1}")
else:
same_num = False
print(f"dice are not the same. die 1 is {die_1} and die 2 is {die_2}")
return same_num
#roll_dice()
#to repeat the rolls of each die
#need the following inputs
num_simulations = 100
max_num_rolls = 10
#tracking?
win_probability = []
end_balance = []
#looping simulation
for i in range(num_simulations):
#setting inital values for each variable
balance = 50
num_rolls = 0
num_wins = 0
bet = 1.00
payout_factor = 4
#run until hitting 1000
for num_rolls in range(max_num_rolls):
if roll_dice():
balance=balance+payout_factor*bet
num_wins += 1
else:
balance=balance-bet
print(f"in {max_num_rolls} rolls, you won {num_wins} times")
print(f"the balance after simulation {i} of {max_num_rolls} rolls was {balance}")
print(f"end of simulation {i}")
plt.plot(max_num_rolls, balance)
plt.xlabel('number of 2 dice rolls')
plt.ylabel('balance $')
legend_entries = []
legend_entries.append('simulation '+str(num_simulations))
plt.show()