2017-03-16 54 views
0

我的任务是创建一个程序,它可以重新检查密码和用户名,它除了一个缺陷外都可以工作。如果用户名或密码不匹配,则显示“再次输入详细信息”并按照我希望的方式循环显示,但如果匹配,则中断并停止程序,但在此之前显示“再次输入详细信息”。我如何解决这个问题,如果用户的细节匹配,然后打印“好!”就像我想要的那样,而不是“像输入细节一样”输入细节。即使结果不同,我的程序仍然循环一行

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 
+2

[询问用户输入的,直到他们得到一个有效的响应]的可能的复制(http://stackoverflow.com/questions/23294658/asking-the -user-for-input-until-they-give-a-valid-response) –

+0

你应该在你的其他帖子中看到我的回答。解决那个问题 – abccd

+0

没有足够的答案吗? – abccd

回答

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 
相关问题