Error saying mesh has no vertices when it has vertices
A vertex has no vertex group.
Given the error is complaining that a collection does not have a single member (index 0) and the distances list is made from the vertices
floor.data.vertices[i].groups[0].weight = ( d - minDist ) / ( maxDist - minDist ) #Line 16

implies the error is that a vertex is assigned to no vertex group. Test for this.
if not floor.data.vertices[i].groups:
    continue

or ensure in some other way that all the vertices are assigned at least one group.
See second script in this answer re getting all the vertices in a group.  Example below edited somewhat to match above
import bpy
from collections import defaultdict

scene = bpy.context.scene

vgs = defaultdict(list)
ob = scene.objects.get(&quot;GridGrass&quot;)
assert(ob is not None) # make sure it exists
me = ob.data
for v in me.vertices:
    for g in v.groups:
        vgs[ob.vertex_groups[g.group].name].append(v)

# print all verts in GrassGrowth vg

print(vgs[&quot;GrassGrowth&quot;])