Python实战作业-day1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python实战作业-day1相关的知识,希望对你有一定的参考价值。

作业需求:

实现用户名密码登录验证

  1. 判断用户名密码是否正确,正确则打印欢迎信息,错误输出具体的错误原因信息
  2. 用户可以连续输入三次密码,超过三次则锁定用户
  3. 用户输入的密码位数必须超过6位

 

作业流程图:

技术分享

 

作业代码:

 1 #!/usr/bin/python
 2 #coding:utf-8
 3 
 4 
 5 import sys
 6 
 7 count = 0
 8 time = 0
 9 
10 
11 while count < 3:
12     loginuser = raw_input("please input your name: ").strip()
13     user_file1 = open(/tmp/reboot15/user_lock,r+)     
14                
15     for line1 in user_file1.readlines():
16         line1 = line1.strip()
17         if loginuser == line1:
18             sys.exit("The user %s has been locked" % loginuser)
19 
20     user_file2 = open(/tmp/reboot15/user,r)
21 
22     for line2 in user_file2.readlines():
23         loginuser01,loginpw1 = line2.strip().split(:)
24         
25         if loginuser == loginuser01:
26             count1 = 0
27             while count1 <3:
28                 time = 2 - count1
29                 count1 += 1
30 
31                 loginpw = raw_input("please input your password: ").strip()
32                 if len(loginpw) <6:
33                     print "your password length must be more than 6, you have %s times left!" % time
34                 else:
35                     if loginpw == loginpw1:
36                         sys.exit("welcome to %s !" % loginuser)
37                     else:
38                         if count1 != 2:
39                             print "your password is wrong , you have %s times left!" % time
40 
41             else:
42                 user_file1.write(loginuser + \\n)
43                 sys.exit("The user %s is locked" % loginuser)    
44 
45     else: 
46         sys.exit("your account does not exist ,please register, thanks.")
47 
48 user_file1.close()
49 user_file2.close()

 

以上是关于Python实战作业-day1的主要内容,如果未能解决你的问题,请参考以下文章

Python Day1 作业

Python学习day1作业总结

Python s12 Day1 笔记及作业

python作业-day1

Python15-day1课后作业

s14 python3 day1 作业2