0

My task was to create a program that can recheck the password and username and it works except for one flaw. If the username or password does not match it says "Input details again" and loops it like I want it to but if it matches it breaks and the program stops but before that it says "Input details again". How can I fix it so if the user details match then it prints "Good!" like I want it to and not "Input details again" like its doing.

import time
complete = False
user = [["username",""],["password",""]]

def Access():
    for n in range (len(user)):
        user[n][1] = input(user[n][0])

while not complete:
    Access()
    username = input("Reinput the username?")
    password = input("Reinput the password?")

    if username == user[0][0]:
        print("Good!")#what i want it to print if correct
    else:
        print("Input details again!")#what it keeps printing no matter what
    if password == user[1][1]:
        print("User has been identified, Welcome", username)
        complete = True
        break
Jainil Patel
  • 13
  • 1
  • 1
  • 2
  • 2
    Possible duplicate of [Asking the user for input until they give a valid response](http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Chris_Rands Mar 16 '17 at 12:36
  • You should see my answer in your other post. Fixed that problem there – Taku Mar 16 '17 at 12:47
  • Was none of the answers good enough there? – Taku Mar 16 '17 at 12:48

1 Answers1

0

I'm pretty sure your subscripting is wrong but I'm not exactly sure what you intend. Anyway, learn to debug. Add a print statement (the one preceded by #debug):

if username == user[0][0]:
    print("Good!")#what i want it to print if correct
else:
    print("Input details again!")#what it keeps printing no matter what
#debug
print( 'password compare "{}" with "{}"'.format( password, user[1][1] ) )
if password == user[1][1]:
    print("User has been identified, Welcome", username)
    complete = True
    break
nigel222
  • 7,582
  • 1
  • 14
  • 22