Job One: an adorner that measures the elapsed time for the program
1 Import Time2 deftimer (next):3 defWrapper (*args,**Kwargs):4Start_time =time.time ()5Next (*args,**Kwargs)6Stop_time =time.time ()7 Print("run time in%s"% (Stop_time-start_time))8 9 returnwrapperTen @timer One defindex (): ATime.sleep (1) - Print("Welcome") - theIndex ()
Job Two: Control user login by means of adorners and read-write files
1 defAuth_type (auth_type):2 defAuth (next):3 defWrapper (*args,**Kwargs):4 ifAuth_type = ='file':5Lock = {}6Flag =True7With open ("Username.txt") as F_user, open ("Locked.txt","A +") as F_lock, open ("f_logged","A +") as f_logged:8 whileflag:9Lock_count =0Ten f_lock.seek (0) One f_user.seek (0) A f_logged.seek (0) -user_name = input ("Please enter your account number:") - forLogged_ininchf_logged: the ifUser_name = =Logged_in.strip (): - Print("Landing Success!") - returnNext (*args,**Kwargs) -passwd = input ("Please enter your password:") + forUser_lockinchF_lock: - ifUser_lock.strip () = =user_name: + Print("This account has been locked!") ALock_count = 1 at Break - forUserinchF_user: -User_f, Passwd_f = User.strip (). Split ("----") - ifUser_f = = User_name andLock_count = =0: - ifPasswd_f = =passwd: - Print("Landing Success!") inF_logged.write (user_name+'\ n') - returnNext (*args,**Kwargs) to Else: + ifUser_nameinchLock: -Lock[user_name] + = 1 the Else: *Lock[user_name] = 1 $ BreakPanax Notoginseng Print("Login failed!") - ifUser_nameinchLock andLock[user_name] >= 3: the Print("excessive number of errors, account lockout!") +F_lock.write (user_name +'\ n') A Lock.pop (USER_NAME) the Print("Login failed!") + elifAuth_type = ="SQL":Print("Brother Feng has not taught") - returnwrapper $ returnAuth $@auth_type (auth_type="file") - defindex (): - Print("Welcome") the -Index ()
Python Jobs 14-10