Python week1-练习1登陆接口
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python week1-练习1登陆接口相关的知识,希望对你有一定的参考价值。
文件下载:practise1.tar
练习一:
- 输入用户名密码
- 认证成功后现实欢迎信息
- 输错三次后锁定
#!/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登陆接口的主要内容,如果未能解决你的问题,请参考以下文章
Coursera课程 R-Programming Week1 编程练习代码