装饰器———小白第三周(带验证功能)

name1,password1 = 'we','w123'
name2,password2 = 'qq','q123'
def auto(auto_new):
def wrap(func):
def atm(*ages,**kwargs):
name_new = input('please input your name:')
password_new = (input('please input your password:'))
if auto_new == 'losd':
if name1 == name_new and password1 == password_new:
func(*ages,**kwargs)
else:
print('your name or password is inviold')
return atm(*ages,**kwargs)
elif auto_new == 'qwer':
if name2 == name_new and password2 == password_new:
func(*ages,**kwargs)
else:
print('your name or password is inviold')
return atm(*ages,**kwargs)
return atm
return wrap
@auto(auto_new = 'losd' )
def index():
print('welcome to the index')
@auto(auto_new = 'qwer')
def log():
print('welcome to the log')
index()
log()

猜你喜欢

转载自www.cnblogs.com/123gk/p/12461724.html
今日推荐