ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 09 Jul 2013 23:25:10 -0500IndentationErrorhttps://ask.sagemath.org/question/10338/indentationerror/I wrote "import networkx as nx FG=nx.Graph() FG.add_weighted_edges_from([(1,2,41),(1,3,75),(2,4,23),(3,4,81),(3,2,43),(4,5,25),(5,2,45)])" in a .sage file. When I go to sage terminal and run it I get IndentationError: unexpected indent (<string>, line 2). What can be the problem and please let me know how I can slove this.Tue, 09 Jul 2013 21:30:56 -0500https://ask.sagemath.org/question/10338/indentationerror/Answer by tmonteil for <p>I wrote "import networkx as nx FG=nx.Graph() FG.add_weighted_edges_from([(1,2,41),(1,3,75),(2,4,23),(3,4,81),(3,2,43),(4,5,25),(5,2,45)])" in a .sage file. When I go to sage terminal and run it I get IndentationError: unexpected indent (<string>, line 2). What can be the problem and please let me know how I can slove this.</p>
https://ask.sagemath.org/question/10338/indentationerror/?answer=15217#post-id-15217As the error message, says, there is a problem with the indentation of your code, your 3 lines must start in the same column, like this:
import networkx as nx
FG=nx.Graph()
FG.add_weighted_edges_from([(1,2,41),(1,3,75),(2,4,23),(3,4,81),(3,2,43),(4,5,25),(5,2,45)])
not like this:
import networkx as nx
FG=nx.Graph()
FG.add_weighted_edges_from([(1,2,41),(1,3,75),(2,4,23),(3,4,81),(3,2,43),(4,5,25),(5,2,45)])
This is a feature of Python (the programming language on which Sage is based): "*statement grouping is done by indentation instead of beginning and ending brackets*".
Tue, 09 Jul 2013 23:25:10 -0500https://ask.sagemath.org/question/10338/indentationerror/?answer=15217#post-id-15217