我想在当前图形中添加边这是我的图形代码
def mGraph():
graph = {'A': {'B': 1, 'C': 2},
'B': {'C': 2, 'D': 1},
'C': {'D': 1},
'D': {'C': 2},
'E': {'F': 1},
'F': {'C': 2}}
return graph
这是添加边功能
def add_edge(graph, aa1, aa2):
graph[aa1].update()[aa2]
graph[aa2].update()[aa1]
return graph
我要求用户输入第一个节点和第二个节点
def main():
graph = mGraph()
option = ''
while option != 'terminate':
print(" a. Display")
print(" c. Add Edges")
option = input("Enter your option:")
if option == "a":
print(graph)
if option == "c":
a1 = input("First Edge")
a2 = input("Second Edge")
print(add_edge(graph, a1, a2))
main()
我想将两条边链接到当前图形并想修改它们。如果用户在“First Edge”中输入 A,在“Second Edge”中输入 D。我想看到图表中的变化。用户输入应该反映在图表上。
我有这样的错误
Traceback (most recent call last):
File "C:......", line 52, in <module>
main()
File "C:......", line 49, in main
print(add_edge(graph, a1, a2))
File "C:......", line 25, in add_edge
graph[aa1].update()[aa2]
TypeError: 'NoneType' object is not subscriptable
杨魅力
相关分类