import math def tri(n): """nth triangular number""" return n * (n + 1) /2.0 def trilist(n): """n terms of the triangular number sequence""" thelist = [] for i in range(1, n+1): thelist.append(tri(i)) return thelist def trilist2(n): """n terms of the triangular number sequence (alternate)""" return [tri(i) for i in range(1, n+1) ] def distance2d(p0, p1): """distance formula in xy plane""" return math.sqrt((p0[0]-p1[0])**2 + (p0[1]-p1[1])**2) def distance3d(p0, p1): """distance formula in xyz """ return math.sqrt((p0[0]-p1[0])**2 + (p0[1]-p1[1])**2 + (p0[2]-p1[2])**2)