欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Python用戶登錄接口的方法

 更新時間:2019年04月17日 08:34:41   作者:qiyue0087  
這篇文章主要介紹了Python用戶登錄接口的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

Readme:

blog address:

摘要:編寫登錄接口

輸入用戶名、密碼

認證成功后顯示歡迎信息

輸錯3次后鎖定

關(guān)鍵詞:循環(huán);判斷;外部數(shù)據(jù)讀寫;列表;字典;

展望:可以結(jié)合數(shù)據(jù)庫讀寫。

codes:

# Author: Steven Zeng
'''
作業(yè)2:編寫登錄接口
輸入用戶名密碼
認證成功后顯示歡迎信息
輸錯3次后鎖定
'''
print("welcome to here")
f1=open('username.txt')
f2=open('password.txt')
f3=open('error.txt')#建立一個Demo記錄輸錯3次密碼的用戶,并對其鎖定
username_true=f1.readlines()#readlines讀取方式返回的是逐行一個元素的列表
password_true=f2.readlines()
un_error=f3.readlines()
f1.close()
f2.close()
f3.close()
UK={}
#建立一個字典形式為用戶名對密碼
for i in range(len(username_true)):
 UK[str(username_true[i])]=str(password_true[i])#注:字典的鍵必須是不可變更型數(shù)據(jù)(常用整數(shù)和字符串)
# 而鍵值可以是數(shù)字也可以是字符串
#print(un_error)
#print(un_error.count(777+'\n')
#print(UK)
count=0
while count<3:
 username = input("Please, input your username:")
 password = input("Please, input your keywords")
 if un_error.count(str(username+'\n'))>=3:
  print("Out of trying, You are Locking!")
  break
 elif str(username+'\n') in UK and str(password+'\n')==UK.get(str(username+'\n')):
  print("welcome to you, honorable customer!")
  break
 else:
  print('''Invalid customer, please try again!
  And you have {count_left1} times left!'''.format(count_left1=2-count))
  f3=open('error.txt','a')#建立一個Demo記錄輸錯3次密碼的用戶,并對其鎖定
  f3.write(username+'\n')
  f3.close()
 count += 1

以上所述是小編給大家介紹的Python用戶登錄接口的方法詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論