0
は
私はuser_command
からFloyd_Warshall(G)
を呼び出すようにしようとしているしかし、私はこのerror
を得る:ユーザー入力から関数を呼び出す方法は?
Traceback (most recent call last):
File "main.py", line 24, in <module>
Floyd_Warshall()
NameError: name 'Floyd_Warshall' is not defined
このエラーを取り除くためにそれを呼び出すためにどのように?
import sys
import re
print("File containing graph: ")
while True:
user_input = input()
if user_input == "input1.txt":
print("Possible Commands are:")
print("dijkstra x - Runs Dijkstra starting at node X. X must be an integer")
print("floyd - Runs Floyd's algorithm")
print("help - prints this menu")
print("exit or ctrl-D - Exits the program")
print("Enter command: ")
user_command = input()
if user_command == "help":
print("Possible Commands are:")
print("dijkstra x - Runs Dijkstra starting at node X. X must be an integer")
print("floyd - Runs Floyd's algorithm")
print("help - prints this menu")
print("exit or ctrl-D - Exits the program")
elif user_command == "floyd":
Floyd_Warshall()
else:
print ("dijkstra")
elif user_input == "input2.txt":
print("Possible Commands are:")
print("dijkstra x - Runs Dijkstra starting at node X. X must be an integer")
print("floyd - Runs Floyd's algorithm")
print("help - prints this menu")
print("exit or ctrl-D - Exits the program")
elif user_input == "input3.txt":
print("Possible Commands are:")
print("dijkstra x - Runs Dijkstra starting at node X. X must be an integer")
print("floyd - Runs Floyd's algorithm")
print("help - prints this menu")
print("exit or ctrl-D - Exits the program")
elif user_input == "exit":
sys.exit(0)
else:
print("Wrong choice")
def Floyd_Warshall(G):
............
............
if __name__ == '__main__':
Floyd_Warshall()
となりますので、それを受け入れることを検討してください。 – Merlin