Creating a Program to Decompose a Number and Run a Function on that Decomposition

CTSB01 scott.moore270 at gmail.com
Fri Jul 19 04:16:41 CEST 2013


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



More information about the Python-list mailing list