-4

So I'm trying to code a login dialogue in the terminal with Python3 but for some reason this code:

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()

prompts me this error message:

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

Just started out some I'm not really sure what I did wrong and I couldn't find somebody with the same problem...

7
  • 3
    You can't run a function that isn't defined yet. You call start() before login is defined, and start tries to call login(). Commented Sep 3, 2020 at 17:05
  • Python is the interpreted language, it's not a compiler, so it can only use function which are defined before it's use Commented Sep 3, 2020 at 17:09
  • Why the downvote? Question is very valid. It may be a duplicate but one cannot know every question asked in the site. Commented Sep 3, 2020 at 17:13
  • @Asocia Downvote because "the question does not show any research effort", and a search on Google or SO would return a lot of relevant results. Commented Sep 3, 2020 at 17:21
  • Also, don't forget to use the proper f-string syntax (the preceding 'f' before string) in the print statement. (or use .format( ... ) ) Commented Sep 3, 2020 at 17:21

1 Answer 1

0

as others pointed out, You need first to define, then to call a function :

# 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()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.