Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55235

Re: Help with python functions?

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 <random832@fastmail.us>
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 <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>
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 <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.568.1380654155.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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