[sage-support] Re: Creating table of values in SAGE

2007-02-21 Thread Justin C. Walker

I'm not sure whether you've gotten an anwser (my mail feeds are  
working at cross-purposes right now), but:

On Feb 21, 2007, at 10:42 AM, Timothy Clemans wrote:


 I'm trying to pass in an expression to my class Table and use i in the
 for loop for the x variable. How can I do that?

 class Table:
 def __init__(self,range_start,range_end,step,expression):
 self.range = range(range_start,range_end+1,step)
   self.expression = expression
 def __repr__(self):
 return 'Table of values of %s for %s' %
 (str(self.expression),str(self.range))
 def __str__(self):
 string = 'x| y\n\n\n\n'
   for x in self.range:
   string += '%5d|%6d\n\n' % (x,self.expression)
   return string
 table1 = Table(0,10,1,2*x+3)

I believe that you should treat the 'expression' as a function, in  
that the string you are building up should be done thusly:

string += '%5d|%6d\n\n' % (x,self.expression(x))

Hope that works for you.

I got a complaint when I tried your example, so I'm not sure how you  
got this output:

 print table1

 x| y
 
 0|21
[snip]

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
---
My wife 'n kids 'n dogs are gone,
I can't get Jesus on the phone,
But Ol' Milwaukee's Best is my best friend.
---



--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---



[sage-support] Re: Creating table of values in SAGE

2007-02-21 Thread Timothy Clemans

Thanks

On 2/21/07, Justin C. Walker [EMAIL PROTECTED] wrote:

 I'm not sure whether you've gotten an anwser (my mail feeds are
 working at cross-purposes right now), but:

 On Feb 21, 2007, at 10:42 AM, Timothy Clemans wrote:

 
  I'm trying to pass in an expression to my class Table and use i in the
  for loop for the x variable. How can I do that?
 
  class Table:
  def __init__(self,range_start,range_end,step,expression):
  self.range = range(range_start,range_end+1,step)
self.expression = expression
  def __repr__(self):
  return 'Table of values of %s for %s' %
  (str(self.expression),str(self.range))
  def __str__(self):
  string = 'x| y\n\n\n\n'
for x in self.range:
string += '%5d|%6d\n\n' % (x,self.expression)
return string
  table1 = Table(0,10,1,2*x+3)

 I believe that you should treat the 'expression' as a function, in
 that the string you are building up should be done thusly:

 string += '%5d|%6d\n\n' % (x,self.expression(x))

 Hope that works for you.

 I got a complaint when I tried your example, so I'm not sure how you
 got this output:

  print table1
 
  x| y
  
  0|21
 [snip]

 Justin

 --
 Justin C. Walker, Curmudgeon at Large
 Institute for the Absorption of Federal Funds
 ---
 My wife 'n kids 'n dogs are gone,
 I can't get Jesus on the phone,
 But Ol' Milwaukee's Best is my best friend.
 ---



 


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---