Ask Your Question
1

IndentationError

asked 2013-07-10 04:30:56 +0100

Soumya gravatar image

updated 2013-07-10 06:48:37 +0100

vdelecroix gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-07-10 06:25:10 +0100

tmonteil gravatar image

updated 2013-07-10 06:29:52 +0100

As 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".

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: 2013-07-10 04:30:56 +0100

Seen: 1,269 times

Last updated: Jul 10 '13