標籤:python3 列表 檔案讀寫
登入要求:
1、使用者輸入登入帳號 、密碼,登入成功顯示歡迎使用者登入介面
2、 使用者可以嘗試三次登入,三次登入失敗後,將鎖定使用者,並輸出到新的檔案當中。
count = 0while count < 3 : file1 = open("accounts.txt", "r") data1 = file1.read().strip().split() username = input("Please input your username>>>> ") password = input("Please input your password>>>> ") if username == data1[0] and password == data1[1]: print("welcom to %s login" %username) break; elif username == data1[2] and password == data1[3]: print("welcom to %s login" % username) break; elif username == data1[4] and password == data1[5]: print("welcom to %s login" % username) break; else: print("user %s login is failure please try again" % username) count = count + 1else: file2 = open("lock_userlist.txt", "w") file2.write(username) print("you have try 3 times your %s is locked\n" %username)
accounts.txt
測試:登入成功
測試 :登入失敗
Python 類比三次使用者登入,登入失敗鎖定帳號並寫入檔案