-2

I have tried many different imputs but they all say print "Invalid". I would appreciate if anyone can explain or edit my code so i can understand.

username = []
password = []

def account_creation():
    account = input("Would you like to make an Account? Yes or No: ")
    if account == "Yes" or "yes":
        username = input("Please make a Username: ")
        password = input("Please make a Password: ")
    else:
        return
account_creation()

def login():
    account = input("Do you have an Account? Yes or No: ")
    if account == "Yes":
        login_username = input("Plese enter your username: ")
        login_password = input("Plese enter your password: ")
    else:
        return
    if login_username and login_password == username and password:
        print("Welcome back")
    else:
        print("Invalid Username or Password")

login()
Owain1105
  • 15
  • 1
  • 4
  • 1
    Your code will print "welcome back" if `login-username==True` and `login_password==username` and `password==True`. it should be `login_username == username and login_password == password` – Equinox Mar 30 '18 at 21:56
  • 1
    Possible duplicate of [How do I test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-do-i-test-multiple-variables-against-a-value) – DeepSpace Mar 30 '18 at 22:02
  • Thank you for clarifying that, it confused me but now i understand where I went wrong. – Owain1105 Mar 30 '18 at 22:03
  • Could you clarify though where i need to add each new part? i'm slightly confused. – Owain1105 Mar 30 '18 at 22:28

1 Answers1

1

you need to first check you username-password check line (as _venky stated):

...    
if login_username == username and login_password == password:
...

but you have something more important missing here. you are trying to change global variables inside a function, thus you need global keyword with related variables in the function body.

def account_creation():
    global username,password
    account = ... the rest of the code
Yılmaz Durmaz
  • 2,374
  • 12
  • 26
  • So I understand the need for the global variable but what do I need to check in the username-password check line? – Owain1105 Mar 30 '18 at 22:41
  • venky had already given that part but I thought I should add that too here. I guess you wrote this while I was editing. – Yılmaz Durmaz Mar 30 '18 at 22:44
  • i've done both the username-password check line and the global variable but it still seems to print invalid username or password and i've done multiple tests. – Owain1105 Mar 30 '18 at 22:49
  • I am sure you messed somewhere else while trying to correct. just copy-paste your own code in your question, then patch the parts I gave you. I have changed only those parts and it is working surely. If you are on linux I recommend you to do a diff test to see where things went wrong – Yılmaz Durmaz Mar 30 '18 at 22:56
  • It's working now!! I think I just accidentally messed up somewhere. Thank you for explaining. – Owain1105 Mar 30 '18 at 23:02
  • you may flag the answer as accepted if you pleased. thanks – Yılmaz Durmaz Mar 31 '18 at 20:32
  • 1
    @Owain1105 please accept Yilmaz's answer if it helped you. – Nerdy Bunz Apr 10 '18 at 03:05