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

詳解Python用戶(hù)登錄接口的方法

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

Readme:

blog address:

摘要:編寫(xiě)登錄接口

輸入用戶(hù)名、密碼

認(rèn)證成功后顯示歡迎信息

輸錯(cuò)3次后鎖定

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

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

codes:

# Author: Steven Zeng
'''
作業(yè)2:編寫(xiě)登錄接口
輸入用戶(hù)名密碼
認(rèn)證成功后顯示歡迎信息
輸錯(cuò)3次后鎖定
'''
print("welcome to here")
f1=open('username.txt')
f2=open('password.txt')
f3=open('error.txt')#建立一個(gè)Demo記錄輸錯(cuò)3次密碼的用戶(hù),并對(duì)其鎖定
username_true=f1.readlines()#readlines讀取方式返回的是逐行一個(gè)元素的列表
password_true=f2.readlines()
un_error=f3.readlines()
f1.close()
f2.close()
f3.close()
UK={}
#建立一個(gè)字典形式為用戶(hù)名對(duì)密碼
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')#建立一個(gè)Demo記錄輸錯(cuò)3次密碼的用戶(hù),并對(duì)其鎖定
  f3.write(username+'\n')
  f3.close()
 count += 1

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

相關(guān)文章

最新評(píng)論