I am unable to see the figure. kindly help me out

import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt

def gamblers_ruin ():
  gambling_money = 50
  gambling_goal =100
  gambling_simulations = []

  while gambling_money in range (1, gambling_goal):
      bet_size =1
      w_or_1= random.randrange(-1, 2, step=2)
      gambling_money += bet_size * w_or_1
      return gambling_simulations

  plt.xlabel('number of bets')
  plt.title('gambling simulations')
1 Like

As you can see, code pasted into a post can’t be understood unless you follow this advice.

(Don’t worry. Everyone needs to be told this at least once.)

Hi !

I think you have to unindent the lines where you define your figure. In the code you sent, all the plt.xxx calls belong to the definition of gamblers_ruin(), but they’re never executed because return is called earlier.

I also assume that the return should be unindented to be out of the while loop, otherwise this loop never iterates more than once.

1 Like

Thanks for quoting the code nicely. Now you’ve done that, it was easy for me to copy it and debug it.

If you correct the remaining problems with the indenting as @WeisLeDocto suggests, and the spelling of linestyle (line 25 in my copy), the code will be correct and you should find it runs. It ran for me on Windows, using Idle, and Python 3.12.

If there’s still a problem, tell us in what environment you are running it (PC, Jupyter, CoLab) and whether you get any error messages. It’s best if you copy and paste error messages and quote them like code. If that’s fixed it for you, let us know too.