# Help with Blender animation type thing. (New to blender)

So I made a 2D physics simulator in python using pygame which simulated a solar system. I wanted to make a 3-D version using blender but I have gotten stuck on how to actually make it run. With pygame I simply trapped it in a while loop and let it play out and closed it when I finished. It didn’t take me long to figure that blender doesn’t like that and freezes when stuck in a while loop.
My code works for creating and moving the objects but I need a way to play out the animation. I was thinking something like making it so that every frame of the animation the last part of my code runs. (or I could simply manually create the solar system and have a code which only causes gravity) I am very new to blender as today is my first day and I only picked it up to make this program. I would love for anyone to point me in the right direction.
Here is my code: (I apologize as there is probably a way to nicely format this which I am not seeing.)

import bpy

def distance(coord1, coord2):
return ((coord1 - coord2)**2 + (coord1 - coord2)**2 + (coord1 - coord2)**2)**0.5

return [coord1 + coord2, coord1 + coord2, coord1 + coord2]

def normalized(coord1, coord2): #Starting at 1 and pointing towards 2.
d = distance(coord1, coord2)
return [(coord2 - coord1)/d, (coord2 - coord1)/d, (coord2 - coord1)/d]

def multiply(coord1, scalar):
return [coord1*scalar, coord1*scalar, coord1*scalar]

Time = 0.1
N = 2
pi = 3.14159265359
pos = []
mass = []
vel = []
den = []

pos.append((0,0,0))
pos.append((3,0,0))

den.append(1)
den.append(1)

4/3)

vel.append((0,-0.15,0)) #Note that having VCM != 0 the system will drift.
vel.append((0,1.5,0))
G = 10

for i in range(N):
bpy.context.scene.cursor_location = pos[i]