码迷,mamicode.com
首页 > 编程语言 > 详细

Python week1-练习1登陆接口

时间:2016-12-21 21:04:02      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:打开   http   用户   read   自己   lock   txt   log   for   

文件下载:practise1.tar

练习一:

  1. 输入用户名密码
  2. 认证成功后现实欢迎信息
  3. 输错三次后锁定
#!/usr/bin/env python
#Author:Austin

name = input("Please input user name:")

deny_file = open("deny.txt","r")
line = deny_file.readline()[:-1]
while line:
    if line == name:
        print("Sorry, the user has locked!")
        exit()
    line = deny_file.readline()[:-1]
deny_file.close()

password = input("Password:")

f = open("passwd.txt","r")
line = f.readline()
while line:
    _user_name = line.split(":")[0]
    _user_password = line.split(":")[1][:-1]

    if _user_name == name:
        if  _user_password == password:
            print("Welcome my friend",name)
            break
        else:
            count = 1
            while count < 3:
                password = input("Password wrong,input angain.")
                if _user_password == password:
                    print("Welcome my friend ",name)
                    break
                else:
                    count += 1
            if count == 3:
                print("You have tried three times, user {name} will be locked".format(name = name))
                deny_file = open("deny.txt","a")
                deny_file.write(name+"\n")
                deny_file.close()
    line = f.readline()
f.close()

后记:

1.第一周学习内容没有打开文件操作,自己搜索一下进行了操作。

2.写完以后觉得流程图确实非常重要,能缩短时间。对于山炮程序员的自己来说,画流程图觉得好麻烦。

3.写的时候觉得应该用子函数调用会更容易。但那时候写的差不多了,就不想改动了。

4.山炮程序员保证下次写程序多一点注释。

Python week1-练习1登陆接口

标签:打开   http   用户   read   自己   lock   txt   log   for   

原文地址:http://www.cnblogs.com/wuhao1234wuhao/p/6208747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!