vertices generated by script not placed correctly
the code is not quite right. Here 2 variants :

1. if you need cubes (separated) as it seams from your example

for this you need 4 verts for current section and 4 more verts that are really the next section, same but steps + 1 (0 at the end)

so the part of the code changed would be:

for steps in range(iterations):
    # this is the next iteration 
    step2 = (steps + 1) if steps &lt; iterations else 0


    # this section
    x1 = math.sin(a * steps)*r
    x2 = math.sin(a * steps)*(r-t)
    y1 = math.cos(a * steps)*r
    y2 = math.cos(a * steps)*(r-t)
    z1 = d
    z2 = 0
    # next section
    x3 = math.sin(a * step2)*(r-t)
    x4 = math.sin(a * step2)*r
    y3 = math.cos(a * step2)*(r-t)
    y4 = math.cos(a * step2)*r


    # cube
    v0 = (x1,y1,z1)    # out
    v1 = (x2,y2,z1)    # in
    v2 = (x3,y3,z1)    # in next
    v3 = (x4,y4,z1)    # out next
    v4 = (x1,y1,z2)    # same for z2 ...
    v5 = (x2,y2,z2)
    v6 = (x3,y3,z2)
    v7 = (x4,y4,z2)

    verts = (v0,v1,v2,v3,v4,v5,v6,v7)

    faces = [   
        (0,1,2,3),      # top
        (7,6,5,4),      # bottom
        (0,3,7,4),      # right
        (5,6,2,1),      # left
        (3,2,6,7),      # front
        (1,0,4,5)]      # back    #flipped to get the right normal


the rest is the same



2. if you use a continuous mesh (like a torus) in case that works too

the principle is the same, but you use only the 4 verts and in the faces include the next iteration (0 at the end). 
Also, can generate all face index at once realy, but that is not the issue here

so the part of the code changed would be:

for steps in range(iterations):

    #### vectors

    x1 = math.sin(a * steps)*(r-t)
    x2 = math.sin(a * steps)*r
    y1 = math.cos(a * steps)*(r-t)
    y2 = math.cos(a * steps)*r
    z1 = d
    z2 = 0

    # rings
    v0 = (x1,y1,z1) # top in
    v1 = (x2,y2,z1) # top out
    v2 = (x2,y2,z2) # bottom out
    v3 = (x1,y1,z2) # bottom in

    verts.extend( [v0,v1,v2,v3] )


    #### polys

    thisStep = steps * 4
    nextStep = ((steps + 1) % iterations) * 4

    polys = [
    (thisStep + 0, nextStep + 0, nextStep + 1, thisStep + 1),   # top
    (thisStep + 1, nextStep + 1, nextStep + 2, thisStep + 2),   # out
    (thisStep + 2, nextStep + 2, nextStep + 3, thisStep + 3),   # bottom
    (thisStep + 3, nextStep + 3, nextStep + 0, thisStep + 0),   # bottom
            ]

    faces.extend( polys )


here you would generate a single object and just set the verts/faces on it

well, for the sake of example :)