from random import randint, random def randomLine(length=None): if not length or length < 2: length = randint(2,10) line = [] for i in range(length): line.append([round(random() * 1000, 2), round(random() * 1000, 2)]) return line def lineLength(line=None): if not line: line = randomLine() if len(line) < 2: return None length = 0 for i in range(len(line) - 1): length += ((line[i][0] - line[i+1][0]) ** 2 + (line[i][1] - line[i+1][1]) ** 2) ** 0.5 return length