Python 3.x 同时中断多个功能

Python 3.x 同时中断多个功能,python-3.x,Python 3.x,我使用了搜索功能,但找不到问题的明确答案。这一点出现了,但并没有真正回答: 我只是想创建一种退出按钮,这就是我的程序的总体布局,我不想透露细节 def function_1(): while True: print('Things...') input1 = input('type a, b or c') if input = 'a': function_2() def function_2(): while True: print('More

我使用了搜索功能,但找不到问题的明确答案。这一点出现了,但并没有真正回答:

我只是想创建一种退出按钮,这就是我的程序的总体布局,我不想透露细节

def function_1():
while True:
    print('Things...')
    input1 = input('type a, b or c')
    if input = 'a':
        function_2()

def function_2():
while True:
    print('More fun things...')
    input2 = input('type 1, 2, "x" to return to previous menu or "exit" to exit')
    if input2 = 'exit':
        ?????
这感觉像是一个简单的问题,但我不知道该怎么办,尝试了一些事情却没有成功。 为了澄清,“退出”应该同时退出这两个功能


谢谢

函数_2
应该
返回一个值,而
函数_1
应该捕获该返回值并相应地进行操作。例如:

def function_1():
    while True:
        print('Things...')
        input1 = input('type a, b or c')
        if input = 'a':
            quit = function_2()
            if quit:
                return

def function_2():
    while True:
        print('More fun things...')
        input2 = input('type 1, 2, "x" to return to previous menu or "exit" to exit')
        if input2 = 'exit':
            return True

类似的解决方案是创建一个自定义异常并在try语句中运行函数_2。如果需要嵌套两个以上的函数,并且仍然能够在几个不同点中断,那么这可能会使它更具可读性。