Python Jobs 14-10

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.