01_python基础练习_01login
2018-06-17 23:39:30来源:未知 阅读 ()
README:
How to use it:
There is a file with username and password named 'username.txt' in directory 'login'.
When user inputs username and password, the program will verify it. If they are wrong, user can try again.
Remember user only have three chances, then the wrong username will be writen in the file named 'name_locked.txt'.
If the username user inputs is in 'name_locked.txt', user has no chance to try again!
1 # Author:Zhang Yide 2 # coding:utf-8 3 4 count = 0 5 done = False 6 lock = False 7 _name = None 8 9 while count < 3: 10 _name = input('Please input username:') 11 _password = input('Please input password:') 12 _namepw = _name + ': ' + _password + '\n' 13 14 #判断_namepw是否在name_locked.txt中 15 f_lock = open('name_locked.txt') 16 for line in f_lock.readlines(): 17 if line == _name + '\n': 18 print('{name} has been locked!'.format(name=_name)) 19 f_lock.close() 20 lock = True 21 f_lock.close() 22 break 23 else: 24 continue 25 26 # 判断_namepw是否在username.txt中 27 f_username = open('username.txt') 28 for line in f_username.readlines(): 29 if line == _namepw: 30 print('Welcome {name}!'.format(name=_name)) 31 done = True 32 f_username.close() 33 break 34 else: 35 continue 36 37 #如果不在username.txt文件中,提示错误。 38 if done == False and lock == False: 39 print('Username or password is wrong! Try again!') 40 count += 1 41 f_username.close() 42 else: 43 break 44 #现已被锁定且之前未被锁定,则写入lock.txt. 45 if done == False and lock ==False : 46 print('The username {name} has been locked'.format(name=_name)) 47 with open('name_locked.txt', 'a') as f_lock: 48 f_lock.write('{name}\n'.format(name = _name)) 49 else: 50 pass
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:深入理解切片原理
- python3基础之“术语表(2)” 2019-08-13
- python3 之 字符串编码小结(Unicode、utf-8、gbk、gb2312等 2019-08-13
- Python3安装impala 2019-08-13
- 小白如何入门 Python 爬虫? 2019-08-13
- python_字符串方法 2019-08-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash