1. 程式人生 > >第二階段---python基礎--模擬登陸

第二階段---python基礎--模擬登陸

pre 存在 基礎 exit 超過 span eval ont os.path

說明:

1、用戶原文件存儲在文件中_userinfo

2、判斷是否存在登陸錯誤的用戶_被鎖定的用戶_wrong_name2,沒有創建,並寫入用戶文件頭username,帶逗號,鎖定用戶以‘逗號‘隔開;

3、判斷輸入用戶是否存在鎖定賬戶中(取出用戶名,存入列表,)

4、邏輯控制,用戶名,或秘密超過3次記錄該用戶的用戶名到文件;

import os
if os.path.exists(‘wrong_name2‘):
file_wrong=open(‘wrong_name2‘)
f=file_wrong.readline()
lock_name=f.split(‘,‘)
for i in lock_name:
print(i)
file_wrong.close()
else:
with open(‘wrong_name2‘,‘w‘) as f_wrong:
f_wrong.write(‘username‘)
f_wrong.write(‘,‘)
lock_name=f_wrong.split(‘,‘)
for i in lock_name:
print(i)
file_wrong.close()


file=open(‘userinfo2‘)
info=eval(file.readline())
print(info)
l_name=[]
l_passwd=[]
l_count=[]
count=0
for i in info:
l_name.append(i[0])
for k in info:
l_passwd.append(i[1])




while True and count<3:
name=input(‘pls input your name:‘).strip()
if name in lock_name:
print(‘the count is locked...exit.‘)
exit()
while name in l_name and count<3:
count=0
while count<3:
passwd=input(‘pls input your passwd:‘).strip()
if passwd in l_passwd:
print(‘welcome‘)
break
else:
count+=1
print(‘wrong passwd‘)
print(count)
else:
l_count.append(name)
print(l_count)
f_w=open(‘wrong_name2‘,‘a+‘)
f_w.write(str(l_count[-1]))
f_w.write(‘,‘)
f_w.close()
print(‘count>>>%s was locked...‘%name)
exit()
else:
count+=1
print(‘wrong name...‘)
continue
else:
l_count.append(name)
f_w=open(‘wrong_name2‘,‘a+‘)
f_w.write(str(l_count[-1]))
f_w.write(‘,‘)
print(‘count>>>%s was locked...‘%name)

第二階段---python基礎--模擬登陸