#三次登录机会是否继续游戏
count = 1
while count<=3:
username = input('请输入用户名:')
password = input('请输入密码')
n = 3-count
if username == 'whzc' and password == 'whzc':
print('欢迎登录')
break
else:
template = "用户名或密码错误,您还有%s次机会."%(n)
#字符格式化
print(template)
if count==3:
choice = input('请输入是否继续(Y/N)')
if choice=='N':
break
elif choice=='Y':
count = 1
continue
else:
print('输入错误')
break
count+=1
#另一种思维,数字递减,减少代码
count = 2
while count>=0:
usr = input('请输入用户名:')
pwd = input('请输入密码:')
if usr=='whzc' and pwd=='whzc':
print('欢迎登录。')
break
template='用户名或密码错误,您还有%s次机会。'%(count,)
#字符格式化%s %括号内变量count后面加逗号
print(template)
if count == 0:
choice = input('请输入是否继续(Y/N)')
if choice=='N':
break
elif choice=='Y':
count = 2
continue
else:
print('输入错误')
break
count-=1
#break是跳出当前循环,而continue是回到while循环开始。