-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete graph.py
More file actions
30 lines (24 loc) · 877 Bytes
/
Copy pathcomplete graph.py
File metadata and controls
30 lines (24 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import networkx as nx
import matplotlib.pyplot as plt
def create_complete_graph():
while True:
try:
n = int(input("Enter number of vertices (must be > 3): "))
if n > 3:
break
else:
print("Vertices must be greater than 3. Try again.")
except ValueError:
print("Invalid input. Please enter an integer.")
# Create a complete graph Kn
G = nx.complete_graph(n)
print(f"\nComplete Graph K{n} created.")
print(f"Nodes: {G.nodes()}")
print(f"Edges: {G.edges()}")
# Visualize the graph
plt.figure(figsize=(8, 6))
nx.draw_circular(G, with_labels=True, node_color='lightblue', edge_color='gray', node_size=1000)
plt.title(f"Complete Graph K{n}")
plt.show()
if __name__ == "__main__":
create_complete_graph()