Would Anonymous Functions Help in Learning Programming/Python?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Sep 21 22:17:36 EDT 2007


Cristian wrote:
> On Sep 21, 3:44 pm, Ron Adam <r... at ronadam.com> wrote:
> 
>> I think key may be to discuss names and name binding with your friend.

Here's an idea:

import math

def sin_integral(start, finish, dx):
     total = 0.0
     y0 = math.sin(start)
     for n in range(1, 1 + int((finish - start) / float(dx))):
         y1 = math.sin(start + n * dx)
         total += (y0 + y1)
         y0 = y1
     return total / 2. * dx


def cos_integral(start, finish, dx):
     total = 0.0
     y0 = math.sin(start)
     for n in range(1, 1 + int((finish - start) / float(dx))):
         y1 = math.cos(start + n * dx)
         total += (y0 + y1)
         y0 = y1
     return total / 2. * dx

generalize and separate the integration technique from the
function it integrates.



More information about the Python-list mailing list