converting parametic equation using python I'm trying to convert some math / formulas
STEP 1:

Found at:
https://math.stackexchange.com/questions/324527/do-these-equations-create-a-helix-wrapped-into-a-torus
But the spirals aren't closing / connecting in Blender 2.83.x.  See image below along with snippet of code / formula.

Snippet of python code in Blender 2.83.x:
# fill verts array

num_x=40
num_y=40
for i in range (0, num_x):
    for j in range(0,num_y):
    
        n = 5 #loop_num
        loop_pos = 2
        u = loop_pos+(i*2*math.pi/num_x)
        v = 2*math.pi*(j/(num_y-1)-1/2)
        
        x = (uval_R_bg+uval_r_sm*math.cos(n*u))*math.cos(u)
        y = (uval_R_bg+uval_r_sm*math.cos(n*u))*math.sin(u)
        z = uval_r_sm*math.sin(n*u)

STEP 2:
My goal is to convert the formula below in Blender 2.83.x using python and animate it.

An example of what it does can be found here
https://demonstrations.wolfram.com/ToroidalHelicalCoils/
I figured it out here's a snippet
#loop_pos = 0 # not enabled yet look at eq_2 in other python script 1 gives  full connection
n = loop_num #is the number of turns per winding.
m = loop_windings #is the number of helical windings.
u = 2*math.pi*(i/(num_x-1-(loop_pos*(num_x+1))))  #loop_pos = 1  eq_2 in other python script 1 gives ou full connection
lamda = 1 #-1 or +1 for winding directions right +1, left -1

x = math.cos(u)*(uval_R_bg - uval_r_sm * math.cos(2*math.pi*helix_offset/m + (lamda*n*u)))    
y = math.sin(u)*(uval_R_bg - uval_r_sm * math.cos(2*math.pi*helix_offset/m + (lamda*n*u)))    
z = uval_r_sm*math.sin(2*math.pi*helix_offset/m + (lamda*n*u))