登录要求:
1、用户输入登录账号 、密码,登录成功显示欢迎用户登录界面
2、 用户可以尝试三次登录,三次登录失败后,将锁定用户,并输出到新的文件当中。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
count
=
0
while
count <
3
:
file1
=
open
(
"accounts.txt"
,
"r"
)
data1
=
file1.read().strip().split()
username
=
input
(
"Please input your username>>>> "
)
password
=
input
(
"Please input your password>>>> "
)
if
username
=
=
data1[
0
]
and
password
=
=
data1[
1
]:
print
(
"welcom to %s login"
%
username)
break
;
elif
username
=
=
data1[
2
]
and
password
=
=
data1[
3
]:
print
(
"welcom to %s login"
%
username)
break
;
elif
username
=
=
data1[
4
]
and
password
=
=
data1[
5
]:
print
(
"welcom to %s login"
%
username)
break
;
else
:
print
(
"user %s login is failure please try again"
%
username)
count
=
count
+
1
else
:
file2
=
open
(
"lock_userlist.txt"
,
"w"
)
file2.write(username)
print
(
"you have try 3 times your %s is locked\n"
%
username)
|
accounts.txt
测试:登录成功
测试 :登录失败
本文转自 水滴石川1 51CTO博客,原文链接:http://blog.51cto.com/sdsca/2051801,如需转载请自行联系原作者