代码1(while循环和IF条件语句,字符格式化,break,continue)

#三次登是否继续
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循环开始。
原文地址:https://www.cnblogs.com/witchingsong/p/12143516.html