python中for else循环_python中for循环是可以带else的

python中for循环是可以带else的,不满足for循环的条件,可以执行ELSE的内容!

#!user/bin/env python

#-*-coding:utf-8 -*-

# Author: Sy106

#read userinfo

account='user.txt'

f=file(account)

accountName=f.readlines()

print 'the Auth Names are:',accountName

for i in range(5):

Login=False

#read lock name into local file

username=raw_input('please input your login name:').strip()

lock='lock.txt'

f=file(lock)

lockName_list=[]

for lockName in f.readlines():

lockName=lockName.strip('\n')

lockName_list.append(lockName)

f.close()

print 'lockName_list are:',lockName_list

if username in lockName_list:

print'The user %s has been lock!please use another username!'%username

break

for line in accountName:

line=line.split()

if username==line[0]:#if the name is right ,input the passwd

for j in range(3):

passwd = raw_input('please input your password:').strip()

if passwd==line[1]:

print "Welcome %s login the system!"%username#login success

Login = True

break

else:

f=file(lock,'a')

f.write('%s\n'%username)

f.close()

print 'Enter 3 times wrong password,the name %s is locked'%username

if Login is True:break#jump out of for loop

else:

print 'please input the right name ,retry!'

if  Login is True:

break#jump out of top for loop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值