Ask Your Question
1

IndentationError

asked 2013-07-09 21:30:56 -0500

Soumya gravatar image

updated 2013-07-09 23:48:37 -0500

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-09 23:25:10 -0500

tmonteil gravatar image

updated 2013-07-09 23:29:52 -0500

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-09 21:30:56 -0500

Seen: 863 times

Last updated: Jul 09 '13