我在Python中使用自定义函数时遇到了麻烦

我在Python中使用自定义函数时遇到了麻烦,python,function,Python,Function,我用Python编写了一个关于用户登录系统的简单程序。我使用了许多自定义函数使代码变得优雅。以下是“选择页面”功能: def choose_page(): print('Welcome to the code system!') print('****************************\n') print('there are the three options:\n' '1.sign up\n' '2.log in\

我用Python编写了一个关于用户登录系统的简单程序。我使用了许多自定义函数使代码变得优雅。以下是“选择页面”功能:

def choose_page():
    print('Welcome to the code system!')
    print('****************************\n')
    print('there are the three options:\n'
          '1.sign up\n'
          '2.log in\n'
          '3.quit')
    print('****************************\n')
    option = eval(input('Please input your option:'))
    return option
def sign_up():
    global customer
    # global option
    # global option2
    ..................
    ..................(many codes)
    option2 = eval(input('Now you can log in the main page by inputting 2 or 0 to return the sign_page: '))
    return option2
这里是“注册”功能:

def choose_page():
    print('Welcome to the code system!')
    print('****************************\n')
    print('there are the three options:\n'
          '1.sign up\n'
          '2.log in\n'
          '3.quit')
    print('****************************\n')
    option = eval(input('Please input your option:'))
    return option
def sign_up():
    global customer
    # global option
    # global option2
    ..................
    ..................(many codes)
    option2 = eval(input('Now you can log in the main page by inputting 2 or 0 to return the sign_page: '))
    return option2
我还编写了“登录”和“退出”自定义函数,然后我可以像这样按照自己的意愿对它们进行排列(这一步没有“退出”函数,因为现在不重要了):

我运行它,但遇到的问题似乎是逻辑错误:

当我进入“选择页面”并输入1时,它会进入“注册”,在“注册”结束时,我输入2或0,它仍然会一次又一次地进入“注册”,没有停止

当我使用这些自定义函数时,是否存在逻辑错误?
提前感谢您的帮助。

每次编写
注册()
时,它都会调用它并运行函数。Python并不聪明。它不会说:“我们以前已经运行过
注册()
。我记得答案。不需要再运行了!”它完全按照您的指示执行。如果您编写
注册()
,它将调用
注册()

为了避免重复提示,您需要将其结果保存到变量中,并且只调用函数一次

if choose_page() == 1:
    sign_up_answer = sign_up()     
    if sign_up_answer == 0:
        choose_page()
    elif sign_up_answer == 2:
        log_in()     
对存在相同问题的任何其他函数重复相同的想法。

不要使用
eval(输入(…)
)。如果您要获取
int
,请使用
int(输入(…)