Path: csiph.com!aioe.org!news.mixmin.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'messages.': 0.05; 'say,': 0.05; 'float': 0.07; 'indices': 0.07; '[0,': 0.09; 'assuming': 0.09; 'item.': 0.09; 'len(x)': 0.09; 'subject:Function': 0.09; 'subject:Number': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '2):': 0.16; '[2,': 0.16; 'accepts': 0.16; 'integers,': 0.16; 'range(0,': 0.16; 'returned,': 0.16; 'subject: \n ': 0.16; 'typeerror:': 0.16; 'url:gmane': 0.16; '\xa0you': 0.16; '(0)': 0.16; 'index': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'items.': 0.19; 'pointed': 0.19; 'value.': 0.19; '>>>': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; '>>>': 0.24; 'errors.': 0.24; 'integer': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'defined': 0.27; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '"",': 0.31; 'subject:that': 0.31; 'file': 0.32; 'probably': 0.32; 'run': 0.32; '(most': 0.33; 'skip:& 30': 0.33; 'third': 0.33; 'comment': 0.34; 'message.': 0.35; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessing': 0.36; 'idle': 0.36; 'right?': 0.36; 'next': 0.36; 'thanks': 0.36; "i'll": 0.36; 'url:org': 0.36; 'list': 0.37; 'implement': 0.38; 'skip:& 10': 0.38; 'list,': 0.38; 'recent': 0.39; 'does': 0.39; 'called': 0.40; 'ian': 0.60; 'first': 0.61; 'to:addr:gmail.com': 0.65; 'sound': 0.68; 'receive': 0.70; 'jul': 0.74; 'links,': 0.74; 'items,': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=qXlZPcOB8f212IOuKJITa5L5ZgIzarG126cjA5ciUFY=; b=fJ/yEclODwvrdsgwSxOXtZKOVy2EPfahR1BOm8jRPMzTAgaBsEwNdMiGL083CvaNrf lFEJb98642LF1Vo/Er5n72ZGdJn9uqAPF/2vP2aWLORXzyzsOqpXB1nyvw8SXICpSnMb 6BAS0OKLdeKmU8cj/vAp6j9FJpG/kl7/EvvIoLtKCkK34KNkS7lWlEkYuN36pKY2F7DF 1Ets8IPDpb4+YFMwp3nhJNNASJZTrBx68qO7qscKYHlnLCiP3+D1nsST7z2s/lnEcfbi zSfN5skxcYcZvfLR7eBnUfzw1cVnPNwJMKLuMdxD8/l4zad1leQHAl4G5hbwvd6+HoAS Esjg== MIME-Version: 1.0 X-Received: by 10.49.16.233 with SMTP id j9mr15626714qed.12.1374202103333; Thu, 18 Jul 2013 19:48:23 -0700 (PDT) In-Reply-To: <97eeec63-7a06-47ad-ad8c-863c58369d01@googlegroups.com> References: <8a23cbf1-3cfd-48e3-a460-64551119fde7@googlegroups.com> <537e9d19-6587-4773-8910-df4005505653@googlegroups.com> <8c5f6217-0029-481f-9bb0-dab1b34180df@googlegroups.com> <2c9344f3-ec42-477f-b9a7-6cf444906298@googlegroups.com> <97eeec63-7a06-47ad-ad8c-863c58369d01@googlegroups.com> Date: Fri, 19 Jul 2013 03:48:23 +0100 Subject: Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: CTSB01 Content-Type: multipart/alternative; boundary=047d7bea38e2380bca04e1d45c62 Cc: python-list@python.org 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: 144 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374202112 news.xs4all.nl 15901 [2001:888:2000:d::a6]:35157 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50886 --047d7bea38e2380bca04e1d45c62 Content-Type: text/plain; charset=ISO-8859-1 On 19 Jul 2013 03:24, "CTSB01" wrote: > > Thanks for the alternative links, I'll use gmane.org as an access point next time. > > > > > Don't paraphrase. Just copy/paste it into your email message. And I'm > > > > assuming you know to run things from the terminal window, and not from > > > > IDLE or something else that messes up the error messages. Your comment > > > > about 'orange' doesn't sound promising. > > > > > > > > As Ian pointed out, you have no return value in this function. You > > > > calculate something called 'rtn', but never use it. The last line > > > > accomplishes nothing, since rtn is neither assigned nor returned, nor > > > > passed nor... You probably wanted: > > > > > > > > return rtn > > > > Does something like > > def phi_m(x, m): > rtn = [] > for n2 in range(0, len(x) * m - 2): > n = n2 / m > r = n2 - n * m > rtn.append(m * x[n] + r * (x[n + 1] - x[n])) > print ('n2 =', n2, ': n =', n, ' r =' , r, ' rtn =', rtn) > return rtn > > look right? > > It doesn't seem to have any errors. However, I do receive the following error when trying to implement an x after having defined phi: > > >>> x = [0, 1, 1, 2, 3] > >>> phi_m(x, 2) > Traceback (most recent call last): > File "", line 1, in > phi_m(x, 2) > File "", line 6, in phi_m > rtn.append(m * x[n] + r * (x[n + 1] - x[n])) > TypeError: list indices must be integers, not float When you think about it, it makes sense. If you have a list, say, [2, 5, 1] You can say, I want the first item (0) or the third item(2) but never, the one-and-a-halfeth (0.5) item. Python only accepts integer values when accessing list items. To access list items, convert your index into an integer value. --047d7bea38e2380bca04e1d45c62 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 19 Jul 2013 03:24, "CTSB01" <scott.moore270@gmail.com> wrote:
>
> Thanks for the alternative links, I'll use gmane.org as an access point next time.
>
> >
> > Don't paraphrase. =A0Just copy/paste it into your email messa= ge. =A0And I'm
> >
> > assuming you know to run things from the terminal window, and not= from
> >
> > IDLE or something else that messes up the error messages. =A0Your= comment
> >
> > about 'orange' doesn't sound promising.
> >
> >
> >
> > As Ian pointed out, you have no return value in this function. = =A0You
> >
> > calculate something called 'rtn', but never use it. =A0Th= e last line
> >
> > accomplishes nothing, since rtn is neither assigned nor returned,= nor
> >
> > passed nor... =A0 You probably wanted:
> >
> >
> >
> > =A0 =A0 =A0 =A0return =A0rtn
> >
>
> Does something like
>
> def phi_m(x, m):
> =A0 =A0 =A0 =A0 =A0 rtn =3D []
> =A0 =A0 =A0 =A0 =A0 for n2 in range(0, len(x) * m - 2):
> =A0 =A0 =A0 =A0 =A0 =A0 n =3D n2 / m
> =A0 =A0 =A0 =A0 =A0 =A0 r =3D n2 - n * m
> =A0 =A0 =A0 =A0 =A0 =A0 rtn.append(m * x[n] + r * (x[n + 1] - x[n])) > =A0 =A0 =A0 =A0 =A0 =A0 print ('n2 =3D', n2, ': n =3D'= , n, ' r =3D' , r, ' rtn =3D', rtn)
> =A0 =A0 =A0 =A0 =A0 return rtn
>
> look right?
>
> It doesn't seem to have any errors. =A0However, I do receive the f= ollowing error when trying to implement an x after having defined phi:
>
> >>> x =3D [0, 1, 1, 2, 3]
> >>> phi_m(x, 2)
> Traceback (most recent call last):
> =A0 File "<pyshell#6>", line 1, in <module>
> =A0 =A0 phi_m(x, 2)
> =A0 File "<pyshell#2>", line 6, in phi_m
> =A0 =A0 rtn.append(m * x[n] + r * (x[n + 1] - x[n]))
> TypeError: list indices must be integers, not float

When you think about it, it makes sense. If you have a list,= say,

[2, 5, 1]

You can say, I want the first item (0) or the third item(2) = but never, the one-and-a-halfeth (0.5) item. Python only accepts integer va= lues when accessing list items.

To access list items, convert your index into an integer val= ue.

--047d7bea38e2380bca04e1d45c62--