寫一個函數完成三次登陸功能,再寫一個函數完成註冊功能
阿新 • • 發佈:2018-06-12
三次 ret div name use == home brush while
def register(): while 1: username = input(‘輸入用戶名:‘) passwd = input(‘輸入密碼:‘) with open(‘homework/a.txt‘, ‘r+‘, encoding=‘utf-8‘) as f: for item in f: if username == item.split("\t")[0]: print("用戶名存在,請重新輸入") break else: f.write(username + "\t" + passwd + "\n") return def login(): index = 3 while index > 0: name = input("請輸入用戶名:") passwd = input("輸入密碼:") with open(‘homework/a.txt‘, ‘r‘, encoding=‘utf-8‘) as f: for item in f: if name == item.split("\t")[0] and passwd == item.split(‘\t‘)[-1].strip(): print("恭喜您登陸成功") return else: print("用戶名密碼錯誤,請重新登錄") index -= 1 if __name__ == "__main__": register() login()
寫一個函數完成三次登陸功能,再寫一個函數完成註冊功能