Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'assuming': 0.09; 'function,': 0.09; 'received:internal': 0.09; 'subject:Help': 0.11; 'def': 0.12; '"or"': 0.16; "'c'": 0.16; '32)': 0.16; 'ignoring': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'with?': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'passing': 0.19; 'section.': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'wondering': 0.29; 'probably': 0.32; 'received:66': 0.35; 'subject:with': 0.35; 'convert': 0.35; 'add': 0.35; 'combination': 0.36; 'returning': 0.36; 'subject:?': 0.36; 'should': 0.36; 'half': 0.37; 'unit': 0.37; 'wrong': 0.37; 'received:10': 0.37; 'implement': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'is.': 0.60; 'from:no real name:2**0': 0.61; 'conversion': 0.61; 'simply': 0.61; "you're": 0.61; 'header:Message-Id:1': 0.63; 'email addr:gmail.com': 0.63; 'temperature': 0.84; '2013,': 0.91; 'these.': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= aiF5LPBCUGRYg1zs4xIseg5wPVg=; b=jxg1ZAZF/3X5s9QEbDx1FS8ARbcPfVk+ du6UPNyxQiXEPUABRpcYSa98FYWrNgfuBzh09Z+4MQzTQC2d/1kzvGM/YUt+VILw vZK5UUXACpI8IRNhv/Fc2BTDY1/odAVZZM1bAllp8P+FUFbMc73KdHuyIMGSbdLb ML813T4bucw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=aiF5LPBCUGRYg1zs4xIseg5wPVg=; b=Thz xylTfU7fJCXU7iG5nNaws5IVqy4/ux6SyIzrz89TPBLLUWxkftvelInbEL3bO/9H XPfr1a4pI3+RIiRU/LYf2BIZXLbOfZa+11Ffw5OALIEGG269ZZn29sBMGbbr2Iud gDaGEg0Vl+pnj5mIYuKGTalh5cob0XABV+wXY57M= X-Sasl-Enc: 7Z2x5nXs7TfCygG7bVypGJ2iI2py8BF5QS4kJ7FACz/+ 1380654152 From: random832@fastmail.us To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-ce174988 In-Reply-To: <1b025b07-3c9c-4390-80e5-8b5661f00d96@googlegroups.com> References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> <5d5e5c4d-a79c-4b1a-b9da-ee2ad766ded8@googlegroups.com> <1b025b07-3c9c-4390-80e5-8b5661f00d96@googlegroups.com> Subject: Re: Help with python functions? Date: Tue, 01 Oct 2013 15:02:32 -0400 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380654156 news.xs4all.nl 15890 [2001:888:2000:d::a6]:56717 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55235 On Tue, Oct 1, 2013, at 13:53, kjakupak@gmail.com wrote: > 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 > def temp(T, from_unit, to_unit): Assuming this is temperature conversion. You should add a docstring. > if from_unit == 'C' or from_unit == 'c': Consider normalizing the unit with .upper() at the top of the function so you don't have to do this "or" case in every single section. > return 32 + (9/5)*T You are ignoring the value of to_unit and returning the value in fahrenheit. > elif from_unit == 'K' or from_unit == 'k': > return T + 273.15 This conversion is simply wrong - it's the conversion _from_ celsius _to_ kelvin. > elif from_unit == 'F' or from_unit == 'f': > return (5/9)*(T - 32) You are ignoring the value of to_unit and returning the value in celsius > else: > return to_unit I don't know what this is. It's probably wrong. To implement a temperature conversion function, I would convert from the unit given to kelvin, then convert from kelvin to the desired unit - that way you don't have to implement every combination separately. > # Question 1.b > def comp(T1, u1, T2, u2): > if u1 != u2: > T1 = temp(T1, u1) You're not passing in u2 here. > elif T2 > T1: > return -1 > elif T1 > T2: > return 1 > else: > return 0 > # Question 2 > def P(p_0, t, i): > Amount = P(1 + (i/100)) > return P(1 + (t * i/12)) I don't know what this is. Is this for homework?