亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Python文件操作模擬用戶登陸代碼實例

瀏覽:9日期:2022-07-22 08:53:37

題目要求

1、輸入用戶名和密碼后回車

2、密碼輸入錯誤,給出提示,并選擇是否重新輸入

3、密碼輸入錯誤三次后,用戶被鎖定,無法繼續登陸

構思

1、用戶輸入賬號和密碼后,需要判斷賬號是否存在

2、判斷賬號是否被禁用(錯誤次數大于三次)

3、判斷賬號密碼是否正確

4、不同的錯誤給出不同的提示

5、每輸入錯一次,文檔中的錯誤次數需要更新

6、如果三次以內用戶登陸成功,密碼原來的錯誤次數被重置

題目完成步驟

1、文檔的編寫

考慮到數據的存儲問題,決定將賬號、密碼、錯誤次數進行分行存儲,三行為一組用戶信息

Python文件操作模擬用戶登陸代碼實例

2、代碼編寫

go = Truewhile go: # 用來判斷賬號是否存在 no_existence_flag = True # 用來判斷是否輸入正確 no_flag = True # 用來判斷是否已經被封 disable_flag = True # 用來判斷次數是否已經超過限制 account = input('account:') password = input('password:') # 判斷賬號是否存在(自己寫入已存在用戶的賬號密碼) file = open('C:/Users/Lenovo/Desktop/user.txt','r') # 用于拼接文本內容 file_data = '' while True: line = file.readline() if not line: break file_data += line line_content = line.strip() # 判斷是否存在賬號 if account == line_content: no_existence_flag = False true_password = file.readline() file_data += true_password true_password_content = true_password.strip() disable_flag_line = file.readline() disable_flag_num = int(disable_flag_line.strip()) # 判斷賬號是否被禁用 if disable_flag_num != 3:print('It is not disable!',disable_flag_num)disable_flag = False# 判斷密碼是否正確if password == true_password_content: no_flag = False print('Welcome in this system,{account}!'.format(account = account)) go = False disable_flag_line = disable_flag_line.replace(str(disable_flag_num),str(0)) file_data += disable_flag_lineelse: disable_flag_line = disable_flag_line.replace(str(disable_flag_num),str(disable_flag_num+1)) file_data += disable_flag_line else:file_data += file.readline() else: file_data += file.readline() file_data += file.readline() file.close() # 賬號不存在的報錯 if no_existence_flag: print('This account is not existence!') print('Do you want to try it again......') flag = input('Please input you think:') if flag == 'N': go = False continue # 賬號被禁用的報錯 if disable_flag: print('You account is disable,please go home by youself!') print('Do you want to try it again......') flag = input('Please input you think:') if flag == 'N': go = False continue # 賬號密碼錯誤的報錯 if no_flag: file = open('C:/Users/Lenovo/Desktop/user.txt','w') print(file_data) file.write(file_data) file.close() print('Your password is not right,please try it again!') print('Do you want to try it again......') flag = input('Please input you think:') if flag == 'N': go = False # 重置輸入次數 else: file = open('C:/Users/Lenovo/Desktop/user.txt','w') print(file_data) file.write(file_data) file.close()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 特黄特色的视频免费播放 | 中文字幕国产一区 | 九九九国产在线 | 国产精品成人在线 | 精品国产免费一区二区三区 | m3u8久久国产精品影院 | 日韩黄色一级 | 成人在线网 | 免费高清欧美一区二区视频 | 婷婷六月久久综合丁香76 | 成人久久久 | 国产最新网站 | 国内精品九一在线播放 | 欧洲无线区一二区 | 九九精品热线免费观看6 | 日本一级毛片视频无遮挡免费 | 亚洲国产成人精品女人久久久 | 欧美俄罗斯一级毛片激情 | 国产v在线播放 | 99久久国产免费福利 | 热久久综合网 | 国产丝袜诱惑 | 麻豆免费视频网站入口 | 美女mm翘臀后进式动态图 | 亚洲国产青草 | 99九九成人免费视频精品 | 韩国一级毛片在线高清免费 | 成人午夜网 | 国产大片中文字幕在线观看 | 国产精品福利久久2020 | 99re热这里只有精品18 | 国产精品久久久久久久午夜片 | 亚洲成年网 | 好大好爽国产美女h福利视频 | 超碰免费公开 | 国产精品酒店 | 啪啪免费网站视频观看 | 1级a的观看视频 | 欧美日韩第二页 | 免费一级欧美片片线观看 | 麻豆精品传媒成人精品 |