# [Edu-sig] More Pythonic Precalculus (Python 2.0)

**Kirby Urner
**
pdx4d@teleport.com

*Mon, 25 Sep 2000 12:11:52 -0700*

Actually that's not quite what lambda is meant for as you've
gone ahead and named the function anyway (f). So much for
lambda providing "anonymous function" capability.
Might just as well go:
>>>* def f(x): return 2 * x * x - 10 * x + 2
*
>>>* graph(f)
*
(which is the approach I take earlier in my precalc.py).
One reason to allow text in particular is you might have a
front end text box (e.g. in Tk) where students get to
freehand their algebraic rule i.e. don't have direct access
to the command line interface. Another reason is rules-as
-strings are easily save out to file e.g. you could have a
text file like:
2*x**2+10*x+3
(x**0.5+x)/(x**2)
sin(x**2)
...
and read in each line for successive evaluation (the sin
string will work if you've done your 'from math import *'
earlier.
In any case, the challenge before me was to accept algebraic
expressions as strings, for whatever reasons.
Kirby
At 01:15 PM 09/25/2000 -0500, you wrote:
>*Kirby --
*>*
*>*How about
*>*
*>>>>* f = lambda x : 2 * x * x - 10 * x + 2
*>>>>* graph(f)
*>*
*>*where:
*>*
*>*def graph(fn):
*>* for x in range(-10, 10):
*>* print x, fn(x)
*>*
*>*or the like.
*>*
*>**much* cleaner; this is *precisely* what lambda is meant for.
*>*
*>*Dustin
*