Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65838
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-02-10 11:01 -0800 |
| References | <e484b709-1287-4e6a-bc43-05f02a608579@googlegroups.com> <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> <mailman.281.1379976512.18130.python-list@python.org> |
| Message-ID | <2c066932-e6dd-4cc6-84dd-2bc5a70bc082@googlegroups.com> (permalink) |
| Subject | Re: Help with python functions? |
| From | tn156@scarletmail.rutgers.edu |
On Monday, September 23, 2013 6:48:20 PM UTC-4, Terry Reedy wrote:
> On 9/23/2013 6:32 PM, kjakupak@gmail.com wrote:
>
> > On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote:
>
> >> On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote:
>
> >>
>
> >> Now you're done! On to the next function...
>
> >>
>
> >>
>
> >>
>
> >> --
>
> >>
>
> >> Steven
>
> >
>
> > def temp(T, from_unit, to_unit):
>
> > conversion_table = {('c', 'k'):lambda x: x + 273.15,
>
> > ('c', 'f'):lambda x: (x * (9.0/5)) + 32,
>
> > ('k', 'c'):lambda x: x - 273.15,
>
> > ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67,
>
> > ('f', 'c'):lambda x: (x - 32) * (5.0/9),
>
> > ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)}
>
> > f = conversion_table[(from_unit.lower(), to_unit.lower())]
>
> > return f(T)
>
>
>
> What happens if you run some tests? If you use unittest, you can use the
>
> assertAlmostEqualMethod, or just write something similar yourself. Be
>
> careful with values near 0..
>
>
>
> At minimum, how many tests do you need, 6 or 9?
>
>
>
>
>
> --
>
> Terry Jan Reedy
can elif be used instead of lambda
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Help with python functions? tn156@scarletmail.rutgers.edu - 2014-02-10 11:01 -0800
csiph-web