Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #55251
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Help': 0.11; 'def': 0.12; '"f"': 0.16; '"r")': 0.16; "'r'": 0.16; '9.0': 0.16; 'erroneously': 0.16; 'lambda': 0.16; 'message-id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'temp': 0.16; 'with?': 0.16; 'subject:python': 0.16; '>>>': 0.22; 'input': 0.22; "aren't": 0.24; 'url:home': 0.24; 'question': 0.24; 'header:X-Complaints-To:1': 0.27; 'wondering': 0.29; '"",': 0.31; 'keyerror:': 0.31; 'file': 0.32; '(most': 0.33; 'subject:with': 0.35; 'returning': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'half': 0.37; 'received:76': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'generating': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'conversion': 0.61; 'making': 0.63; 'email addr:gmail.com': 0.63; 'these.': 0.91; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: Help with python functions? |
| Date | Tue, 01 Oct 2013 19:19:14 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <e484b709-1287-4e6a-bc43-05f02a608579@googlegroups.com> <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> <l1qsdl$f3k$1@dont-email.me> <5d5e5c4d-a79c-4b1a-b9da-ee2ad766ded8@googlegroups.com> <l1s8tj$4ob$1@dont-email.me> <l1spuh$4ob$4@dont-email.me> <1b025b07-3c9c-4390-80e5-8b5661f00d96@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-76-249-20-155.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.580.1380669562.18130.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1380669562 news.xs4all.nl 16001 [2001:888:2000:d::a6]:39594 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:55251 |
Show key headers only | View raw
On Tue, 1 Oct 2013 10:53:26 -0700 (PDT), kjakupak@gmail.com declaimed the
following:
>I ended up with these. I know they're only like half right...
>I was wondering if any of you had to do this, what would you end up with?
>
># Question 1.a
Well... Off-hand you aren't making use of "to_unit" -- For Celsius
input you are automatically returning Fahrenheit; for Kelvin input you are
erroneously adding the C->K conversion value, and for Fahrenheit you
automatically generating Celsius. If "from_unit" is not in the set "CcKkFf"
(no Rankene measure? <G>) you are returning whatever "to_unit" contained...
>>> to_base = {"c" : lambda x : x + 273.15,
... "f" : lambda x : (5.0 * (x - 32.0) / 9.0) + 273.15,
... "k" : lambda x : x }
>>> from_base = {"c" : lambda x : x - 273.15,
... "f" : lambda x : (x - 273.15) * 9.0 / 5.0 + 32.0,
... "k" : lambda x : x }
>>> def temp(T, from_unit, to_unit):
... fu = from_unit.lower()[0]
... tu = to_unit.lower()[0] # presumes both are string
... return from_base[tu]( to_base[fu]( T ) )
...
>>> temp(32, "F", "C")
0.0
>>> temp(0, "C", "K")
273.15
>>>
>>> temp(0, "C", "F")
32.0
>>> temp(212, "F", "C")
100.0
>>> temp(212, "F", "K")
373.15
>>>
>>> temp(100, "F", "R")
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "<interactive input>", line 4, in temp
KeyError: 'r'
>>>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with python functions? kjakupak@gmail.com - 2013-09-23 05:57 -0700
Re: Help with python functions? Roy Smith <roy@panix.com> - 2013-09-23 09:11 -0400
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-23 13:56 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 15:32 -0700
Re: Help with python functions? Terry Reedy <tjreedy@udel.edu> - 2013-09-23 18:48 -0400
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-24 03:08 +0000
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-24 03:17 +0000
Re: Help with python functions? giacomo boffi <pecore@pascolo.net> - 2013-09-24 18:53 +0200
Re: Help with python functions? MRAB <python@mrabarnett.plus.com> - 2013-09-24 18:18 +0100
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 15:55 -0700
Re: Help with python functions? Dave Angel <davea@davea.name> - 2013-09-24 00:07 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 18:23 -0700
Re: Help with python functions? Dave Angel <davea@davea.name> - 2013-09-24 03:52 +0000
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 02:12 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-09-23 19:40 -0700
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 14:51 +0000
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 19:42 +0000
Re: Help with python functions? kjakupak@gmail.com - 2013-10-01 10:53 -0700
Re: Help with python functions? random832@fastmail.us - 2013-10-01 15:02 -0400
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-01 21:45 +0000
Re: Help with python functions? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-01 19:19 -0400
Re: Help with python functions? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-24 03:15 +0000
Re: Help with python functions? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-24 15:02 +0000
csiph-web