Skip to content

why isn't this code working? in Networkx  #536

@layally

Description

@layally

Hello,
I am a beginner in python and I faced an issue with the code. I am trying to create nodes in a specific location, but there is an error and I am not sure how to solve it.
My code:
import networkx as nx
G = nx.Graph()
G.add_node(1, pos[2,6])
G.add_node(2, pos[4,6])
G.add_node(3, pos[6,6])
G.add_node(4, pos[8,6])

G.add_edges_from([(1,5), (1,13), (1,17), (1,21)])
G.add_edges_from([(2,10), (2,6), (2,18), (2,22)])
G.add_edges_from([(3,11), (3,15), (3,7), (3,23)])
G.add_edges_from([(4,12), (4,16), (4,20), (2,24)])

The problem occur In the nodes creation part it tells me [ KeyError: (2, 6) ]. Anyone who can fix this issue and lets the code run successfully ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions