On Oct 7, 2008, at 10:59 AM, Bob Wonderly wrote: > You support people fixed my long arithmetic problem. The patch applied > and worked!
Great. > Now here is another puzzlement: > > alist = > [divmod(0,6),divmod(1,6),divmod(2,6),divmod(3,6),divmod(4,6),divmod > (5,6)] > #of course that's one line > print alist > for k in range(6): > x = divmod(k,6) > print x > > [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5)] > Traceback (click to the left for traceback) > ... > AttributeError: 'int' object has no attribute 'quo_rem' This is because range() returns python ints, not sage Integers. You can use srange() or the "[0..5]" notation to get a list of Python integrs. Alternatively, divmod should probably be modified to do the function below if neither operand is a python object, and maybe even use the coercion model otherwise (so on int, integer, it would do integer, integer). Though it isn't important for your example, the reason for calling quo_rem rather than x//y, x%y is because the latter may do the same work twice doubling the runtime. > def moddiv(x,y): > return (x//y,x%y) > > for k in range(9): > x = moddiv(k,6) > print x > > (0, 0) > (0, 1) > (0, 2) > (0, 3) > (0, 4) > (0, 5) > (1, 0) > (1, 1) > (1, 2) > > Well, at least I have a workaround. > > By the way, in an earlier exchange you'all told me how to use the > notebook() approach. I like it much better than the command line > Sage I > was using. > > Thanks for keeping me happily getting answers with Sage. > > Bob Wonderly > > > > --~--~---------~--~----~------------~-------~--~----~ 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://www.sagemath.org -~----------~----~----~----~------~----~------~--~---