Measure the total distance betwin 3 or more

So i want to calculate the total length of selected vertices, without using the MS calculator manualy.
I try “measureIt” addon, but dont work for that. Do you know any way for doing that?
Like this:

# edge loop length

import bpy

obj = bpy.context.active_object 
looplength = 0
if obj.type == 'MESH':
    objmode = bpy.context.object.mode
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    edges = [e for e in if == True]
    verts =
    for edge in edges: 
        looplength += (verts[edge.vertices[0]].co - verts[edge.vertices[1]].co).length
    bpy.ops.object.mode_set(mode=objmode, toggle=False)

i run the script on text editor inside of blender but nothing happend?