title: Running a loop of a function multiple times
body: <p>I have code to plot particle trajectories until all the spaces in a portion of a 3D matrix are filled. This is based on the final position of the particle. A simplified simulation of particles in a beam of radiation traveling through a body.</p>
  
  <p>I was able to use a for loop to plot a whole bunch of particle trajectories together, and to get the number it takes to fill up all the spaces. I did this by, 
  '''</p>
  
  <pre><code>n = 100
  for n in range(particles):
      Path(ax,body)
      if body==[[[0 for k in range(10)] for j in range(10)] for i in range(10)]:
          print('Tumor destroyed after particle number', n)
          break
  plt.show()
  </code></pre>
  
  <p>'''</p>
  
  <p>and I get the number of particles (n). But I want to loop this many times and then get an average of the number (n) it takes to fill all the spaces in the matrix (destroy the tumor). I tried doing '''</p>
  
  <pre><code>trials=10
  for i in range(trials): 
      for n in range(particles):
          Path(ax,body)
          if body==[[[0 for k in range(10)] for j in range(10)] for i in range(10)]:
              print('Tumor destroyed after particle number', n)
              break
  </code></pre>
  
  <p>'''
  but i just get the same n value from the first part of code 10 times. How do I get it to do the first bit of code new each time and get different n values to average them. </p>
  
  <p>EDIT
  The numbers should all be different since I am using random numbers for the calculations. The calculations are being done inside the Path function. I just want to runt the first snipet of code multiple times and am not sure how to execute it. I can add the full code, but it is very long. </p>