因此,我尝试使用Python3在终端中编写登录对话,但出于某些原因,此代码:
def start():
login_signin_Confirmation = input("Welcome! Do you wish to log-in to your account or sign up to this platform? \n")
if login_signin_Confirmation == "login":
login()
else:
signup()
start()
def login():
login_username = input("Great! start by typing in your username.")
if login_username in users:
print("Welcome Back, {login_username}")
login()
提示我此错误消息:
Welcome! Do you wish to log-in to your account or sign up to this platform?
login
Traceback (most recent call last):
File "login.py", line 22, in <module>
start()
File "login.py", line 19, in start
login()
NameError: name 'login' is not defined
刚开始时,我不太确定自己做错了什么,也找不到同样问题的人...
答案 0 :(得分:0)
正如其他人指出的那样,您需要先定义,然后再调用一个函数:
# imports first
# now definitions of functions
def start():
login_signin_Confirmation = input("Welcome! Do you wish to log-in to your account or sign up to this platform? \n")
if login_signin_Confirmation == "login":
login()
else:
signup()
def signup():
pass
def login():
login_username = input("Great! start by typing in your username.")
if login_username in users:
print("Welcome Back, {login_username}")
# main
def main():
start()
# guard multiprocess context
if __name__ == '__main__':
main()