You could use *n for your parameter. It allows you to enter an arbitrary number of arguments:
def a(*n): return [1/k^2 for k in n] a(2,4,6) ---> [1/4,1/16,1/36] a(5) ---> [1/25] Not exactly what you were wanting, but pretty close. But - why *not* just go ahead and define a(n) for the nth term and then use map or list comprehension to expand the sequence? It seems to me that's a lot clearer. On Wed, Nov 2, 2011 at 12:04 PM, A. Jorge Garcia <[email protected]> wrote: > > Sorry, what I meant to say was: what if I define a function such as > def a(n): > return 1/n**2 > so running > a([2,4,6]) > yields > [1/4,1/16,1/36] > Thanx, > A. Jorge Garcia > Applied Math and CompSci > -- ================================== "What I cannot create, I do not understand." - Richard Feynman ================================== "Computer science is the new mathematics." - Dr. Christos Papadimitriou ================================== -- You received this message because you are subscribed to the Google Groups "sage-edu" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sage-edu?hl=en.
