文件下载:practise1.tarpython
练习一:程序员
#!/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.写完之后以为流程图确实很是重要,能缩短期。对于山炮程序员的本身来讲,画流程图以为好麻烦。spa
3.写的时候以为应该用子函数调用会更容易。但那时候写的差很少了,就不想改动了。code
4.山炮程序员保证下次写程序多一点注释。orm