I am new to programming and I'm trying to solve a problem which says "find the average number of edges that an empty undirected graph needs to become connected"....it also asks to "keep track of isolated components along the way"...
I can add nodes :
from random import random, choice
import networkx as nx
G = nx.Graph()
i = int(input("enter the number of desired nodes : "))
for node in range(0, i):
G.add_node(i) # creates a graph with desired number of nodes
i = i - 1
the output is like 10 9 ... 1 then I try to select two random nodes and connect them with an edge like this :
first_node = choice(G.nodes())
second_node = choice(G.nodes())
print(first_node, second_node) # print which nodes are selected
but it's not working...any idea?