第一个简单的python脚本
#!/usr/bin/python # import os file_1=‘user.txt‘ file_2=‘lock.txt‘ #put an account_list f=file(file_1) accout_list=f.readlines() f.close() #put a list of the lock user f = file(file_2) lock_list= [] for i in f.readlines(): line = i.strip(‘\n‘) lock_list.append(line) f.close() #main Name=raw_input("input the user name:").strip() Password=raw_input("input the user‘s password:").strip() while True: if len(Name) == 0: print "you user name is blank,do it again" Name=raw_input("input the user name:").strip() continue elif len(Password) == 0: Password=raw_input("input the user‘s password:").strip() print "your password is blank,do it again" continue else: break while True: # insert a label to jungle the loginchange loginchange = False if Name in lock_list: print "the user is lock in !" exit() for line in accout_list: line = line.split() # insert a correct username if Name == line[0]: loginchange = True for i in range(3): if Password == line[1]: break else: print "the password is not correct,insert again!" Password=raw_input("input the user‘s password:").strip() if i == 2: print "the user is lock in !" # insert the wrong user into the lock_file f = file(file_2,‘a‘) f.write(‘%s\n‘ %Name) f.close() exit() # continue break else: continue if loginchange is True: break else: print "the user is not exist" answer=raw_input("do you want to insert again?(y/n)") if answer == "y" : Name=raw_input("input the user name:").strip() Password=raw_input("input the user‘s password:").strip() continue else: exit() print "welcome"
本文出自 “永无止境” 博客,请务必保留此出处http://joe51cto.blog.51cto.com/7680547/1413015
原文地址:http://joe51cto.blog.51cto.com/7680547/1413015