1. You can use srange which works like range but gives a list of Sage integers. 2. To coerce an int to a Sage Integer just use ZZ():
sage: srange(1,4) [1, 2, 3] sage: [type(i) for i in srange(1,4)] [<type 'sage.rings.integer.Integer'>, <type 'sage.rings.integer.Integer'>, <type 'sage.rings.integer.Integer'>] sage: range(1,4) [1, 2, 3] sage: [type(i) for i in range(1,4)] [<type 'int'>, <type 'int'>, <type 'int'>] sage: [type(ZZ(i)) for i in range(1,4)] [<type 'sage.rings.integer.Integer'>, <type 'sage.rings.integer.Integer'>, <tyape 'sage.rings.integer.Integer'>] Lastly, there are also xrange() and sxrange() which give iterators rather than lists, useful if the range is big. On Fri, 15 Feb 2019 at 23:27, Michael Beeson <profbee...@gmail.com> wrote: > Well, the real cure is to use IntegerRange instead of range. > Sorry to bother those of you who actually can read a manual. > > > On Friday, February 15, 2019 at 2:56:14 PM UTC-8, Michael Beeson wrote: >> >> def test(p,q): >> t = p/q; >> print(p,q,p/q,t) >> def test2(): >> for p in range(1,4): >> for q in range(1,4): >> test(p,q) >> >> sage: test2() >> >> (1, 1, 1, 1) >> >> (1, 2, 0, 0) >> >> (1, 3, 0, 0) >> >> (2, 1, 2, 2) >> >> (2, 2, 1, 1) >> >> (2, 3, 0, 0) >> >> (3, 1, 3, 3) >> >> (3, 2, 1, 1) >> >> (3, 3, 1, 1) >> >> sage: test(*2*,*3*) >> >> (2, 3, 2/3, 2/3) >> >> sage: version() >> >> 'SageMath version 8.0, Release Date: 2017-07-21' >> >> >> When test(2,3) is executed at top-level, 2/3 is not cast to an integer. >> But when >> >> it is executed inside test2, 2/3 becomes 0. Why? and how to prevent it? >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.