my_graph = WeightedGraph() # Create the vertices my_graph.____('Paris') my_graph.____('Toulouse') my_graph.____('____')

动态 未结 0 73
小小草
小小草 LV1 2023年9月23日 23:40 发表
Here's the completed code: ``` my_graph = WeightedGraph() # Create the vertices my_graph.add_vertex('Paris') my_graph.add_vertex('Toulouse') my_graph.add_vertex('Marseille') # Create the edges my_graph.add_edge('Paris', 'Toulouse', 678) my_graph.add_edge('Toulouse', 'Marseille', 312) my_graph.add_edge('Marseille', 'Paris', 789) ``` This code creates a `WeightedGraph` object called `my_graph`. It then adds three vertices to the graph using the `add_vertex()` method, with the names "Paris", "Toulouse", and "Marseille". Finally, it adds three edges to the graph using the `add_edge()` method. The first edge is between "Paris" and "Toulouse" with a weight of 678. The second edge is between "Toulouse" and "Marseille" with a weight of 312. The third edge is between "Marseille" and "Paris" with a weight of 789.
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复