Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'else:': 0.03; 'elif': 0.05; 'float': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spec': 0.09; 'subject:Help': 0.11; 'python': 0.11; 'def': 0.12; "('c',": 0.16; '23,': 0.16; '32)': 0.16; '32,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'mon,': 0.24; "i've": 0.25; 'header:X-Complaints-To:1': 0.27; '-0700,': 0.31; "d'aprano": 0.31; 'sep': 0.31; 'steven': 0.31; 'skip:c 30': 0.32; 'monday,': 0.33; 'subject:with': 0.35; 'one,': 0.35; 'version': 0.36; 'next': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; "you're": 0.61; 'email addr:gmail.com': 0.63; 'temperature': 0.84; 'wrong...': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Help with python functions? Date: Tue, 24 Sep 2013 00:07:44 +0000 (UTC) References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.35 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379981286 news.xs4all.nl 15901 [2001:888:2000:d::a6]:51336 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54667 On 23/9/2013 18:55, 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) > > Would this be correct? > Also, the temperature number had to be of type float so I feel like I did this wrong... > > As for the next one, so far I've gotten: > def comp(T1, u1, T2, u2): > if u1 > u2: > return -1 > elif u2 > u1: > return 1 > else: > return 0 I didn't see any spec that said Python 3.x. in version 2.x, this would be incorrect. -- DaveA