Ask Your Question
1

IndentationError

asked 11 years ago

Soumya gravatar image

updated 11 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 11 years ago

tmonteil gravatar image

updated 11 years ago

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

Preview: (hide)
link

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: 11 years ago

Seen: 1,281 times

Last updated: Jul 10 '13