我正在尝试让用户输入调用函数。
我的代码:
class the_proccess():
the_route = input("Which function do you want to use? \n\n 1) The first one. \n\n 2) The second one. \n\n 3) The first one and then the second one. \n\n Please enter the corresponding number and hit enter >>>>> ")
if the_route == 1:
first()
elif the_route == 2:
second()
elif the_route == 3:
first()
second()
def first():
print("First function")
def second():
print("Second function")
但是,当我选择该选项时,进程会停止。我不太确定我做错了什么,这是我第一次尝试做这样的事情。
最佳答案
现在这可以如你所愿。
class the_proccess(object):
def first(self):
print("First function")
def second(self):
print("Second function")
def __init__(self):
self.the_route = input("Which function do you want to use? \n\n 1) The first one. \n\n 2) The second one. \n\n 3) The first one and then the second one. \n\n Please enter the corresponding number and hit enter >>>>> ")
if self.the_route == 1:
self.first()
elif self.the_route == 2:
self.second()
elif self.the_route == 3:
self.first()
self.second()
a = the_proccess();
关于python - 用户输入调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48502404/