-1
username = raw_input()
password = raw_input()

user_acct = {'ADMIN':'PASSWORD','READONLY':'PASSWORD','READWRITE':'PASSWORD} 

if username and password != user_acct:
          print('Invalid Login... Please Try Again')
else:

          print('Correct Login')
miradulo
  • 28,857
  • 6
  • 80
  • 93
Ann
  • 21
  • 5
  • With the above code, no matter what I type, 'Invalid Login... Please Try Again' is displayed – Ann May 20 '16 at 17:48
  • I don't know about Python, but I thought most languages required conditionals to be evaluated separately. `if a != b and c!=d:`. Also, isn't user_acct an array? You are testing whether an array equals a string, which will probably always be false. – Buttle Butkus May 20 '16 at 18:01
  • Thank you for your input but this question was answered correctly last week with the code below. if username in user_acct and password == user_acct[username]: print('Correct Login') else: print('Invalid Login... Please Try Again') – Ann May 25 '16 at 13:17

1 Answers1

0

Python will lazily evaluate your if clause, that consists of two conditions!

if username will be True if it is not empty.

No need to check for the password then. As a result, Invalid Login... Please Try Again is printed.

You might want to

  1. check if the username is a key in the dictionary
  2. check it the password fits to this key

    if username in user_acct and password == user_acct[username]:
        print('Correct Login')
    else:
        print('Invalid Login... Please Try Again')
    
Klaus-Dieter Warzecha
  • 2,265
  • 2
  • 27
  • 33
  • I made your changes and when I typed in the correct username and password, I got ('Invalid Login... Please Try Again'). So I entered a incorrect username and password, I got 'Correct Login'). It's like reverse logic. – Ann May 23 '16 at 14:27
  • Ooops, I didn't flip the print statements in my correction. Now it works as I wanted it to. Thank you. You're GREAT! – Ann May 23 '16 at 14:37