Use len(G) instead of number_of_nodes.