用python編寫模擬用戶登錄
阿新 • • 發佈:2017-09-08
es2017 顯示 列表 退出 count png comment 賬戶 tin
readme:涉及python知識點
- 數據類型
- 用戶與程序交互
- while循環
- if..else判斷
大致流程圖:
基礎需求:
- 讓用戶輸入用戶名密碼
- 認證成功後顯示歡迎信息
- 輸錯三次後退出程序
user_info={ ‘oath‘:{‘password‘:‘123‘}, ‘oath1‘:{‘password‘:‘123‘}, ‘oath2‘:{‘password‘:‘123‘}, } count = 0 while True: if count>2: break name=input("Please enter the user name:") if not name in user_info : print ("The user does not exist") count+=1 continue passwd=input("Please enter a secret:") if passwd == user_info[name]["password"]: print ("welcome to you") break else: print(‘wrong password‘) count+=1
升級需求:
- 可以支持多個用戶登錄 (提示,通過列表存多個賬戶信息)
- 用戶3次認證失敗後,退出程序,再次啟動程序嘗試登錄時,還是鎖定狀態(提示:需把用戶鎖定的狀態存到文件裏)
用python編寫模擬用戶登錄