码迷,mamicode.com
首页 > 编程语言 > 详细

Python 简单学习

时间:2017-05-21 21:46:29      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:about   else   赋值   app   退出   login   read   user   and   

import sys
retry_limit = 3
retry_count = 0
account_file=‘accounts.txt‘ #需要自己建立
lock_file=‘account_lock.txt‘ #需要自己建立


while retry_count <retry_limit:#只要不重复三次就不断的循环
username=raw_input(‘\033[32;1mUsername:\033[0m‘)
lock_check=file(lock_file)#当用户输入之后打卡lock_file文件

#循环读取lock_file
for line in lock_check.readlines():
if username in line:
#如果存在就直接退出
sys.exit(‘\033[31;1mUser %s is Locked!\033[0m‘ %username)
password=raw_input(‘\033[32;1mPassword:\033[0m‘)
   #到达这里就说明account_lock.txt里面没有用户

f=file(account_file,‘rb‘)#打开账号文件
    match_flag=False#设置一个标志
for line in f.readlines():
user,passwd=line.strip("\n").split()#去掉每行多余的\n 并且把得到值赋值给user,passwd
if username==user and password==passwd:
#判断用户和密码是否相等
print ‘Match!‘,username
match_flag=True #如果匹配上就把标志设置为True
#匹配上就break
break
f.close()#关闭读取的文件
if match_flag ==False:#如果表示为False 那么证明匹配错误
print ‘User umMatcher‘
retry_count +=1
else:
print "Wlecome login system about apple"
else:
print ‘Your account is Locked‘

Python 简单学习

标签:about   else   赋值   app   退出   login   read   user   and   

原文地址:http://www.cnblogs.com/tomjeam/p/6885867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!