DAY1 练习

要求:⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化),
如果三次用完了之后 问是否再试试 再给三次机会 如果不想试了说没有机会了。


list = [{'username':'xyn','password':'789'},
{'username': 'xxx', 'password': '123'},
{'username': 'yyy', 'password': '456'},]
count=0 #已经输入几次
b=6 #总共输入次数
a=3 #提醒剩余次数
while count<3:
username = input("请输入username:")
password = input("请输入password:")
for i in list:
if username==i['username'] and password==i['password']:
print("登陆成功")
count=3 #为了跳出while循环
break #跳出for循环
else:
b=b-1
a=a-1
print('登录失败,重新输入,剩余%s次机会'%a )
count += 1
if b==0:
print('没有机会了!')
break
if count==3:
choice=input('是否继续尝试3次,yes or no:')
a=3
if choice=='yes' :
count=0
else:
print('再见!')
break

---------------------------------------------------------------------

猜你喜欢

转载自www.cnblogs.com/xyn123/p/8954314.html