py-text11用户登录(三次机会)每次输错显示剩余机会

py-text11

用户登录(三次机会)每次输错显示剩余机会,循环中的break和continue

username=’xiaoz’
password=’123’
i=1
while i<=3:
name=input(‘username: ‘)
pwd=input(‘password: ‘)
if username==name and password==pwd:
print(‘login successful!!!’)
break
else:
print(‘login failed %s times only’ %(3-i))
if (3-i)==0:
result=input(‘try again? yes?:’)
if result==’yes’ or result==’y’ :
i=1
continue
i+=1
else:
print(‘Get out’)

猜你喜欢

转载自blog.csdn.net/xiaoz2008/article/details/82193231