Ask Your Question
1

integer digits range problem (see sage error below) Thanks!!!

asked 2019-06-04 03:07:14 +0200

anonymous user

Anonymous

updated 2019-06-04 10:03:06 +0200

tmonteil gravatar image

.

sage: for i in [9,10,11]:
....:     i.digits(base=3)
....:
[0, 0, 1]
[1, 0, 1]
[2, 0, 1]
sage: for i in range(9,12):
....:     i.digits(base=3)
....:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-e5aab74726b7> in <module>()
      1 for i in range(Integer(9),Integer(12)):
----> 2     i.digits(base=Integer(3))
      3

AttributeError: 'int' object has no attribute 'digits'
sage: [9,10,11]==range(9,12)
True
edit retag flag offensive close merge delete

Comments

1

Too bad I need 60 points to post a png file which is much more readable than the cut and paste from the latest sage math (8.7 I believe) for windows.. I'm running windows 7. For some reason, for i in [9,10,11]: i.digits(base=3) Works Jusf Fine However; for i in range(9,12): i.digits(base=3) Raises an Error Thanks William Stein and all others involved in the development for the free software. Love Sage Math, Sage Math Cell, and Python!!!

Newton gravatar imageNewton ( 2019-06-04 03:14:36 +0200 )edit

The pasted code (once formatted as code) is much more useful than a png file.

With code pasted as text, others can in turn copy and paste pieces of code to their Sage sessions to explore the problem.

Code pasted as a png might "look nice" but is hardly usable for practical purposes.

slelievre gravatar imageslelievre ( 2019-06-05 11:34:02 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-06-04 10:33:38 +0200

tmonteil gravatar image

When you type 9 in Sage, the preparser makes it a Sage integer, that have a .digit method. The range function returns Python ints, who do not have such a method. As you discovered, the srange function returns Sage integers.

edit flag offensive delete link more

Comments

Thanks! That makes sense now.

Newton gravatar imageNewton ( 2019-06-04 13:04:40 +0200 )edit
1

answered 2019-06-04 07:26:45 +0200

Newton gravatar image

replace range with srange and it works in sage math for windows 8.7

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-06-04 03:07:14 +0200

Seen: 550 times

Last updated: Jun 04 '19