即使结果不同,我的程序也会循环一条线

时间:2017-03-16 12:33:49

标签: python task

我的任务是创建一个可以重新检查密码和用户名的程序,除了一个缺陷外,它可以正常工作。如果用户名或密码不匹配,则显示“再次输入详细信息”并按照我想要的方式循环,但如果匹配则中断并且程序停止但在此之前它会显示“再次输入详细信息”。如何修复它,如果用户的详细信息匹配,则打印出“好!”就像我想要它而不是“再次输入细节”一样。

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

1 个答案:

答案 0 :(得分:0)

我很确定你的下载是错的,但我不确定你的意图。无论如何,学会调试。添加一个打印语句(前面加#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