procedural geometry problem

I have the following code which reads a list of 40 points (x and y coordinates on the same line) then it creates a vertex from those points as well as a vertex using the y value of each line and an x value of 6. Then I try to assign faces to the vertices (four vertices per face). The problem is that the top and bottom faces are messing up (face 1 and face 39) Why is that?
Here are the coordinates:
6 299
24 300
35 298
47 296
61 293
72 290
83 285
95 277
106 265
113 256
121 245
128 231
134 220
135 210
136 199
139 195
141 192
141 182
133 173
126 164
120 155
113 144
108 137
103 131
95 123
87 115
79 107
75 102
66 94
60 87
54 82
47 74
42 68
36 60
31 54
26 49
20 41
15 31
11 22
6 13


import Blender
from Blender import *
import math

mesh = Blender.NMesh.New()
Blender.Redraw()

vertex=[]
for i in range(1,81):
  vertex.append(0)
vert=[0,0]
face=[]
for i in range(1,40):
    face.append(0)

f=open('c:\\vertices.txt')
f.seek(0)
for i in range(1,41):
  str=f.readline()
  vert = str.split()
  vert[0] = float(vert[0])
  vert[1] = float(vert[1])
  vertex[i] = Blender.NMesh.Vert(vert[0], vert[1], 0)
  vertex[i+39] = Blender.NMesh.Vert(6, vert[1], 0)
for i in range(1,41):
  mesh.verts.append(vertex[i])
  mesh.verts.append(vertex[i+1])
  mesh.verts.append(vertex[i+40])
  if i!=40:
      mesh.verts.append(vertex[i+41])
for i in range(1,39):
  face[i] = Blender.NMesh.Face()
for i in range(1,39):  
  face[i].v.append(vertex[i])
  face[i].v.append(vertex[i+1])
  face[i].v.append(vertex[i+40])
  face[i].v.append(vertex[i+41])
for i in range(1,39):
  mesh.faces.append(face[i])
mesh.update()

obj = Blender.Object.New('Mesh', 'Plane')
obj.link(mesh)
scn = Blender.Scene.GetCurrent()
scn.link(obj)

can you explain better what your doing? - I tried to run your code and got an index out of range error.

if i!=40:
mesh.verts.append(vertex[i+41])

I have a set of data points that are the profile of an image, there are the data points in the file
the data points are x and y coordinates on the same line, there are 40 lines
so there are 40 data points
i’m turning those into vertices, also I want to make every point have a corresponding vertex at x=6, y= y value of one of the 40 coordinates.
then i’m trying to follow normal steps to turn those into faces and then update the mesh
I"m sorry, i must have updated the wrong version of the text file