編者按:README:此代碼為用戶登陸界面,添加了尋求幫助選項。1.學習了基本數據類型,string, int,以及while迴圈,continue, break, if, elif, else條件語句,“x".format(x)變數替代2.上網搜的dictionary用法,由於用的是python3 ...
編者按:
README:此代碼為用戶登陸界面,添加了尋求幫助選項。
1.學習了基本數據類型,string, int,以及while迴圈,continue, break, if, elif, else條件語句,“x".format(x)變數替代
2.上網搜的dictionary用法,由於用的是python3.6,老教程不太管用,嘗試了2天方纔悟出正確的增加鍵值用法,希望技術大牛留言給予更多啟發!
1 dict_profile = {"Alex":"alex1234", "Bob":"bob123", "Cathy":"cathy1234", 2 "David":"david12345", "Eva":"eva123"} 3 #Save the rightful username and password in the dictionary 4 black_list = { } #Create a list for not exist username 5 email = "send an email to our help desk for further solutions" 6 chance = 6 #After 3 valid trys the system will be locked 7 username = input("username:") 8 password = input("password:") 9 #password = getpass.getpass("password:") 10 while chance > 0: 11 if username not in dict_profile.keys(): #Search for username in the profile 12 black_list["{}".format(username)]="{}".format(password) 13 username = input("The username does not exist, please try again:") 14 chance = chance - 1 15 if username in black_list.keys(): #Run a security check 16 username = input("The username does not exist and has been locked, please try other combinations:") 17 chance = chance - 2 # Deduct 2 chances to punish whoever abuses the system 18 elif password != dict_profile.get(username,""): #Find the value of password to match with the username 19 print("The password does not match the username, do you have problem with memorizing things?") 20 customized_option = input("Y/N") 21 if customized_option != "N": 22 print("Please ask your partner or {}.".format(email)) 23 break 24 else: 25 password = input("Please enter your password with caution:") 26 chance = chance - 1 27 else: 28 print("Welcome my lord {_name}! Please wait while login...".format(_name = username)) 29 break 30 if chance <= 0: 31 print("The system is locked since you have too many incorrect entries!Please {}.".format(email))登陸介面