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) print table1 x | y ------------ 0| 21 1| 21 2| 21 3| 21 4| 21 5| 21 6| 21 7| 21 8| 21 9| 21 10| 21 I created a for loop outside of my class: for i in range(11): x = i print '%5d|%6d\n\n' % (x,2*x+3) 0| 3 1| 5 2| 7 3| 9 4| 11 5| 13 6| 15 7| 17 8| 19 9| 21 10| 23 I don't know why x in self.expression equals 10. I have done several tests and found that in my class x always equals 10. You can check that in SAGE notebook 1 history. --~--~---------~--~----~------------~-------~--~----~ 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/ -~----------~----~----~----~------~----~------~--~---