Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50886
| References | (6 earlier) <8c5f6217-0029-481f-9bb0-dab1b34180df@googlegroups.com> <mailman.4852.1374191380.3114.python-list@python.org> <2c9344f3-ec42-477f-b9a7-6cf444906298@googlegroups.com> <mailman.4853.1374195892.3114.python-list@python.org> <97eeec63-7a06-47ad-ad8c-863c58369d01@googlegroups.com> |
|---|---|
| Date | 2013-07-19 03:48 +0100 |
| Subject | Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition |
| From | Fábio Santos <fabiosantosart@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4855.1374202112.3114.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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. 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 "<pyshell#6>", line 1, in <module>
> phi_m(x, 2)
> File "<pyshell#2>", 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-17 16:58 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Joshua Landau <joshua@landau.ws> - 2013-07-18 10:12 +0100
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 14:57 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Gary Herron <gherron@digipen.edu> - 2013-07-18 15:12 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 15:18 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-18 16:49 -0600
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 16:04 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-18 17:42 -0600
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-18 17:45 -0600
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 17:25 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-07-19 00:48 +0100
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Dave Angel <davea@davea.name> - 2013-07-18 19:49 -0400
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 17:35 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Dave Angel <davea@davea.name> - 2013-07-18 21:04 -0400
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 19:16 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Dave Angel <davea@davea.name> - 2013-07-18 22:43 -0400
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 19:56 -0700
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition Fábio Santos <fabiosantosart@gmail.com> - 2013-07-19 03:48 +0100
Re: Creating a Program to Decompose a Number and Run a Function on that Decomposition CTSB01 <scott.moore270@gmail.com> - 2013-07-18 19:54 -0700
csiph-web