Ask Your Question
0

Two quick questions about the tutorial

asked 2012-12-15 18:54:56 +0200

jdioses gravatar image

I'm using the Interactive Shell.

First question: How do I get back to the working session after I'm done consulting the documentation? For example, if I look up for tan? I get all the information I need and after that a highlighted END. I just don't know how to get back to where I was before.

Second question: The last example in the section Functions, Indentation, and Counting of the Guided Tour doesn't seem to work. It's the example Class Evens(list) .... I've tried typing exactly as it is several times and I keep getting a syntax error message.

Any help would be appreciated. Thank you very much.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
1

answered 2012-12-15 19:48:39 +0200

updated 2012-12-15 19:50:18 +0200

I'm guessing that for both questions, you are using the command-line interface.

First question: type "q". If you type "help()" from the "sage:" prompt, you'll get a message including this paragraph:

(When you type something like "matrix_plot?", "help(matrix_plot)", or "matrix_plot??", Sage may start a paging program to display the requested message. Type a space to scroll to the next page, type "h" to get help on the paging program, and type "q" to quit it and return to the "sage:" prompt.)

(If you're using the notebook instead, just go to the next cell.)

Second question: are you typing the dots "..."? Don't do that. Make sure that the spacing is exactly as displayed in the tutorial.

sage: class Evens(list):
...       def __init__(self, n):
...           self.n = n
...           list.__init__(self, range(2, n+1, 2))
...       def __repr__(self):
...           return "Even positive numbers up to n."
...

When I'm using Sage, after I type the first line, the cursor is already in the right place to type the second line, and the same after the second line. After the fourth line "list.__init__(...)", you will need to hit the backspace key 4 times to get to the right indentation level. After the last line "return ...", hit return twice.

(If you're using the notebook instead, type this in one cell in your worksheet:

class Evens(list):
    def __init__(self, n):
        self.n = n
        list.__init__(self, range(2, n+1, 2))
    def __repr__(self):
        return "Even positive numbers up to n."

Don't type "sage:" and don't type the dots "...".)

edit flag offensive delete link more

Comments

Aside, method __repr__ is a bit strange in this tutorial, we rather expect : return "Even positive numbers up to " + str(self.n)

Bétréma gravatar imageBétréma ( 2012-12-17 12:56:03 +0200 )edit

I would probably use `return "Even positive numbers up to %s." % self.n` or something similar.

John Palmieri gravatar imageJohn Palmieri ( 2012-12-17 13:53:39 +0200 )edit
0

answered 2012-12-17 10:04:46 +0200

jdioses gravatar image

The problem appears when I try to create an object of class Evens. If I type, as the tutorial suggests

e=Evens(10)

I get the following message

TypeError: 'sage.rings.integer.Integer' object is not iterable
edit flag offensive delete link more

Comments

1

Change to the top level Sage directory and run "./sage -t devel/sage/doc/en/tutorial/tour_help.rst". If it says "All tests passed!", then this example is working as it should, and so you must be making a mistake when you type it in.

John Palmieri gravatar imageJohn Palmieri ( 2012-12-17 11:17:07 +0200 )edit
0

answered 2012-12-15 19:06:18 +0200

jdioses gravatar image

Sorry, it's not a syntax error what I get but a type error.

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

Stats

Asked: 2012-12-15 18:54:56 +0200

Seen: 402 times

Last updated: Dec 17 '12