function plus simple username password authentication

def renzheng(func): # Higher-order functions pass the function name func as a parameter 
    def wrapper(*args,** kwargs):
        username =input( ' Username: ' ).strip()
        passwd=input('密码:').strip()
        if username=='qwe' and passwd=='123':
           res = func(*args,** kwargs)
            return res
         else :
             print ( ' error ' )
     return wrapper 
@renzheng #Decorator
def index (): print ( ' Welcome to the homepage ' ) home( " Little Li " )#Execute the home function after executing the authentication function once
@renzheng
def home(name): print ( ' Welcome home %s ' % name) shop( " Xiao Wang " ) #Execute the shop function after executing the authentication function once
@renzheng 
def shop(name): print ( ' %s has %s in the shopping cart, %s ' %(name, ' milk tea ' , ' sister ' ))
  index() #Execute
the index function after executing the authentication function once
index() 
home()
shop()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325899594&siteId=291194637