程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

python 自学day1(关于if和file的应用练习)

发布于2019-08-05 19:30     阅读(1097)     评论(0)     点赞(5)     收藏(2)


1.编写简单的登陆接口

#判断用户信息

#用户输入错误后锁定账号

流程图:

代码:

#!/usr/bin/env python

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

document1 = open('userinfo.txt', 'r')
document2 = open('falseuser.tex', 'w+')
document3 = open('lock.txt', 'w+')
i = 1
n = 1
while i < 4 and n < 4:
username = input('username:')
password = input('password:')
str1 = document1.read()
h = len(username)
if str1.find(username) >= 0 and document2.read().find(username) == -1:
if str1.find(password, (str1.find(username)+h+1), len(password)):
print('welcome to our web!')
break
else:
document2.write(username)
i += 1
else:
if document2.read().find(username) >= 0:
if str1.find(password, (str1.find(username)+h+1), len(password)) and document3.read().find(username) == -1:
print('welcome to our web!')
elif document3.read().find(username) != -1:
print('you have try 3 times')
break
else:
i += 1
print('confirm password')
else:
print('plese input right username')
n += 1
while i == 3:
document3.write(username)
document3.close()
document2.close()
document1.close()
pycharm python3.7版本可用。

 







所属网站分类: 技术文章 > 博客

作者:sdhjsdh

链接:https://www.pythonheidong.com/blog/article/7057/9bd4e4ad9f80077ba846/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)