python入门 第一节 作业一

作业一:编写登录接口
1)输入有户名密码
2)认证成功后显示欢迎信息
3)输错三次后锁定

程序
username_dict={"wangzhuoqun":"wangzhuoqun1","xuehao":"xuehao1","xiewenwu":"xiewenwu1","shenshunqi":"shenshunqi1","wangxuheng":"wangxuheng1"}

n=1
a=0
b=0
c=0
d=0
e=0
while n>0:
username = input("Username:")
password = input("Password:")
g=open('D:\\locked2.txt','r')
content = g.read()
if username in content:
print("Your username have been locked!!!")
else:
if username not in username_dict:
print("No this username!!!")
else:
if username_dict[username] == password:
print("Welcome!!!")
break
else:
print("The password is error!!!")
n += 1
if username == "wangzhuoqun":
a += 1
if a == 3:
print("Your username have been locked!!!")
f = open('D:\\locked2.txt', 'a')
f.write(username)
f.write('\n')
f.close()
elif username == "xuehao":
b += 1
if b == 3:
print("Your username have been locked!!!")
f = open('D:\\locked2.txt', 'a')
f.write(username)
f.write('\n')
f.close()
elif username == "xiewenwu":
c += 1
if c == 3:
print("Your username have been locked!!!")
f = open('D:\\locked2.txt', 'a')
f.write(username)
f.write('\n')
f.close()
elif username == "shenshunqi":
d += 1
if d == 3:
print("Your username have been locked!!!")
f = open('D:\\locked2.txt', 'a')
f.write(username)
f.write('\n')
f.close()
else:
e += 1
if e == 3:
print("Your username have been locked!!!")
f = open('D:\\locked2.txt', 'a')
f.write(username)
f.write('\n')
f.close()
 

猜你喜欢

转载自www.cnblogs.com/wang0424/p/10680364.html