code: def connected_watts_strogatz_graph(n, k, p, tries=100, seed=None):
      """Returns a connected Watts–Strogatz small-world graph.
  
      Attempts to generate a connected graph by repeated generation of
      Watts–Strogatz small-world graphs.  An exception is raised if the maximum
      number of tries is exceeded.
  
      Parameters
      ----------
      n : int
          The number of nodes
      k : int
          Each node is joined with its `k` nearest neighbors in a ring
          topology.
      p : float
          The probability of rewiring each edge
      tries : int
          Number of attempts to generate a connected graph.
      seed : integer, random_state, or None (default)
          Indicator of random number generation state.
          See :ref:`Randomness<randomness>`.
  
      Notes
      -----
      First create a ring over $n$ nodes [1]_.  Then each node in the ring is joined
      to its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd).
      Then shortcuts are created by replacing some edges as follows: for each
      edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors"
      with probability $p$ replace it with a new edge $(u, w)$ with uniformly
      random choice of existing node $w$.
      The entire process is repeated until a connected graph results.
  
      See Also
      --------
      newman_watts_strogatz_graph
      watts_strogatz_graph
  
      References
      ----------
      .. [1] Duncan J. Watts and Steven H. Strogatz,
         Collective dynamics of small-world networks,
         Nature, 393, pp. 440--442, 1998.
      """
      for i in range(tries):
          # seed is an RNG so should change sequence each call
          G = watts_strogatz_graph(n, k, p, seed)
          if nx.is_connected(G):
              return G
      raise nx.NetworkXError("Maximum number of tries exceeded")
  
imports: import itertools
  import math
  from collections import defaultdict
  import networkx
  from networkx.utils import py_random_state
  from .classic import complete_graph, empty_graph, path_graph, star_graph
  from .degree_seq import degree_sequence_tree
label_desc: Use image node_id 7 for calling a global function with example usage: connected_watts_strogatz_graph(n, k, p, tries, seed) and returns: G