Complete the code to define a ring topology with 4 nodes.
ring_topology = ['Node1', 'Node2', 'Node3', [1]]
The ring topology connects nodes in a closed loop. The fourth node should be 'Node4' to complete the ring.
Complete the code to add a link between the last and first node to form a ring.
links = [('Node1', 'Node2'), ('Node2', 'Node3'), ('Node3', 'Node4'), [1]]
In a ring topology, the last node connects back to the first node to close the loop.
Fix the error in the code to correctly check if the network is a ring.
is_ring = (len(links) == len(nodes) and links[[1]] == ('Node4', 'Node1'))
The last link in the list is at index -1, which should connect 'Node4' to 'Node1' to confirm the ring.
Fill both blanks to create a function that returns True if the network is a ring.
def check_ring(nodes, links): return len(links) == len(nodes) and links[[1]] == (nodes[-1], [2])
The last link should be at index -1, connecting the last node to the first node (nodes[0]) to form a ring.
Fill all three blanks to create a dictionary comprehension that maps each node to its next node in the ring.
next_node = {nodes[[1]]: nodes[[2]] for [3] in range(len(nodes))}We use 'i' as the current index, and '(i + 1) % len(nodes)' to get the next node index, wrapping around to form a ring.