<｜begin▁of▁sentence｜>### Instruction:
Given a path graph with nodes [0, 1, 2, 3] connected in a linear sequence, how can you modify the graph to prevent the addition or removal of nodes or edges, while still allowing data modification on nodes or edges?
### Response:
import networkx as nx

# Create a path graph with 4 nodes
G = nx.path_graph(4)

# Freeze the graph to prevent further modification
G = nx.freeze(G)

# Try to add an edge to the frozen graph
try:
    G.add_edge(4, 5)
except nx.NetworkXError as err:
    print(str(err))

# Output: NetworkXError: Frozen graph can't be modified
<|EOT|>
