lambda with floats
Patrick Maupin
pmaupin at gmail.com
Wed Apr 7 00:10:42 EDT 2010
On Apr 6, 11:04 pm, Patrick Maupin <pmau... at gmail.com> wrote:
> On Apr 6, 10:16 pm, monkeys paw <mon... at joemoney.net> wrote:
>
> > I have the following acre meter which works for integers,
> > how do i convert this to float? I tried
>
> > return float ((208.0 * 208.0) * n)
>
> > >>> def s(n):
> > ... return lambda x: (208 * 208) * n
> > ...
> > >>> f = s(1)
> > >>> f(1)
> > 43264
> > >>> 208 * 208
> > 43264
> > >>> f(.25)
> > 43264
>
> Not sure why you are returning a lambda (which is just a function that
> does not have a name) from an outer function.
>
> A function that does this multiplication would simply be:
>
> def s(n):
> return 208.0 * 208.0 * n
>
> Regards,
> Pat
I realized I didn't show the use. A bit different than what you were
doing:
>>> def s(n):
... return 208.0 * 208.0 * n
...
>>> s(1)
43264.0
>>> s(0.5)
21632.0
>>> s(3)
129792.0
I'm not sure exactly what you mean by "acre meter" though; this
returns the number of square feet in 'n' acres.
Regards,
Pat
More information about the Python-list
mailing list