#打印0-100的偶数
for i in range(0,101,2):#0表示开头,101表示结尾,2表示步长
print(i)
#登录三次验证
#方法一:
_user="abc"
_password="123"
passed_authentication=False#表示flag(标志位)
for i in range(3):
username=input("username:")
password=input("password")
if username==_user and password==_password:
print("welcome")
passed_authentication=True
break#表示中断循环
else:
print("账号或者密码错误")
if not passed_authentication:
print("试了三次了,别试了")
#方法二:
_user="abc"
_password="123"
for i in range(3):
username=input("username:")
password=input("password")
if username==_user and password==_password:
print("welcome")
break#表示中断循环
else:
print("账号或者密码错误")
else:
print("试了三次了,别试了")
小结:
1、方法二,for......else......表示只要for循环正常执行完毕(被break中断也是正常执行完毕),那么就不会执行else语句。