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

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版本可用。

猜你喜欢

转载自www.cnblogs.com/czh96/p/11243524.html