def trapezoid(y, h): total = (y[0] + y[len(y) - 1]) / 2.0 for i in range(1, len(y) - 1): total += y[i] return total * h