title: Reusing a variable from a for loop, out of the for loop
body: <pre><code>    for x in range(len(Bodies):
          planet = Bodies[x]
          if planet == planetinit:
              expression
  
          else:
  
              fx = -gravconst*rx/r3
              templistx.append(fx)
              forcex = sum(templistx)
              templistx.clear()
      vx += (forcex/Bodies[n].M)*dt
  </code></pre>
  
  <p>I want to use the forcex, outside of the loop, but this is not possible and I get the error:
  NameError: name 'forcex' is not defined</p>