On Sat, Nov 10, 2018 at 8:06 AM David Joyner <wdjoy...@gmail.com> wrote: > > > > On Sat, Nov 10, 2018 at 10:59 AM Michael Beeson <profbee...@gmail.com> wrote: >> >> def test(): >> for b in range(5,6): >> for c in range(b+1,b+2): >> print(b,c,n(c/b)) >> print(5,6,n(6/5)) >> >> And the output >> >> sage: test() >> >> (5, 6, 1.00000000000000) >> >> (5, 6, 1.20000000000000) >> >> sage: version() >> >> 'SageMath version 8.0, Release Date: 2017-07-21' >> >> >> And the question: why are the two lines not identical? > > > My guess is that python 2.7 interprets c/b to be 1, by the sage preparser > interprets 6/5 to be an element of QQ. Just a guess.
Your guess is correct. In Sage (with python2), we have sage: type(list(range(5,6))[0]) <type 'int'> sage: type(5) <type 'sage.rings.integer.Integer'> > With Python 3, they > should be the same. Yep, though 6/5 in Python3 ints is a *double* and 6/5 in Sage is a rational. However n(...) are the same. This is Python3 Sage: sage: a = int(6)/int(5); a 1.2 sage: type(a) <class 'float'> sage: n(a) 1.20000000000000 sage: n(6/5) 1.20000000000000 And the original loop using Python3 sage: sage: def test(): ....: ^Ifor b in range(5,6): ....: ^I^Ifor c in range(b+1,b+2): ....: ^I^I^Iprint(b,c,n(c/b)) ....: ^Iprint(5,6,n(6/5)) ....: sage: test() 5 6 1.20000000000000 5 6 1.20000000000000 > >> >> >> -- >> 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. -- William (http://wstein.org) -- 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.