1. 程式人生 > >實現用戶登錄並且輸入錯誤三次後鎖定該用戶

實現用戶登錄並且輸入錯誤三次後鎖定該用戶

賬號 else input 實現 break div arm pen locked

我的測試環境,win7,python3.6,Pycharm社區版

提示輸入用戶名,和密碼

判斷是否被鎖定

判斷用戶名和密碼是否匹配

輸入錯誤三次,賬號被鎖定

real_user = ‘channel‘    #正確的用戶名
real_passwd = ‘asdf‘    #正確的密碼

lock_user = [‘tiaozhan‘] #鎖定賬號列表

while True:
    user_input = input("輸入用戶名")
    passwd_input = input(‘your passwd:‘)
    if user_input in lock_user:
        print(‘用戶 %s 被鎖定‘ %user_input)

    elif user_input == real_user:
        i = 0
        while i <3:
        # for i in range(3):
            # passwd_input = input("your password:")
            if passwd_input == real_passwd:
                print(‘yes, you got it‘)
                break
                exit()
            else:
                print("passwd is False")
                if i==2:
                    print("the user has been locked")
                    lock_user.append(user_input)
                    exit()
                else:
                    passwd_input = input("your passwd again:")
            i +=1
    else:
        print("用戶不存在")

  怎麽才能實現類似“淘寶”那樣的登錄提示呢?

實現用戶登錄並且輸入錯誤三次後鎖定該用戶