到目前为止我所拥有的:
def run_A():
# code...
def run_B():
# code...
def run_C():
# code...
inputDict = {'a': run_A, 'b': run_B, 'c': run_C, 'q': False} # q for quit program
def userChoice(self):
y = True
while y:
choice = input("a. run A\nb. run B\nc. run C\nq. Quit").lower()
self.inputDict[choice]
Run Code Online (Sandbox Code Playgroud)
我的问题是该程序允许用户输入他们的选择,但该函数将根据字典调用(不会运行)并且程序只会不断询问用户他们的选择。