length.py

from math import sqrt

def fnf(x):
    return x**2

xinitial=0
xfinal=1
numberofsteps = 2
deltax = (xfinal - xinitial) / numberofsteps
total = 0
for k in range(numberofsteps):
    xl  = xinitial + (k-1)*deltax
    xr = xinitial + k*deltax
    yl = fnf(xl)
    yr = fnf(xr)
    segment = sqrt((xr-xl)**2 + (yr-yl)**2)
    total = total + segment
    print k, segment

print numberofsteps, total

Generated by GNU enscript 1.6.3.