Not a hard and fast rule, but it will usually end up that way. Remember you cannot call a function until you define it, hence @snippsat's reply.
If you take your original code (with corrections):
def main():
# These are the two options available
print("1: register")
print("2: login")
signIn = int(input("Do you have an existing account? 1 or 2?"))
# yes = Y
# no = N
if signIn == 2:
existingUser()
elif signIn == 1:
newUser()
main()
def existingUser():
print("signin")
def newUser():
print("new user")
You will get a NameError:
Error:
1: register
2: login
Do you have an existing account? 1 or 2?1
Traceback (most recent call last):
File "C:/Python/Sound/scratch2.py", line 20, in <module>
main()
File "C:/Python/Sound/scratch2.py", line 17, in main
newUser()
NameError: name 'newUser' is not defined
Process finished with exit code 1
That is because to Python, newUser has not been defined yet (and neither does existingUser). Since you are calling them within the main function, they must exist
before the main function.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition