标签:car lse war 购物 循环 pass rip 用户 strip
userlist = [
{‘name‘:‘doudou‘,‘passwd‘:‘123‘},
{‘name‘:‘chouchou‘,‘passwd‘:‘456‘},
{‘name‘:‘liuhaiquan‘,‘passwd‘:‘789‘},
{‘name‘:‘liuxue‘,‘passwd‘:‘2020‘}
]
current_list = {‘username‘:None,‘login‘:False} #定义一个空的全局变量
def jingdong(yanzheng):
def yonghu(*args,**kwargs):
if current_list[‘username‘] and current_list[‘login‘]: #判断是否已经有用户输入
res = yanzheng(*args,**kwargs) #运行装饰器
return res
username = input(‘用户名: ‘).strip()
passwd = input(‘密码: ‘).strip()
for user_dic in userlist:
if username == user_dic[‘name‘] and passwd == user_dic[‘passwd‘]:
current_list[‘username‘] = username
current_list[‘login‘] = True
res = yanzheng(*args,**kwargs) #运行装饰器
return res
else: #如果for循环结束为止,还是没有验证成功,则打印密码或用户错误
print(‘用户或密码错误‘)
return yonghu
@jingdong
def desk(name):
print(‘欢迎来到京东 %s‘ %name)
@jingdong
def shopcar(name):
print(‘%s 的购物车里有[%s,%s,%s]‘ %(name,‘水果‘,‘饮料‘,‘饼干‘))
@jingdong
def mina(name):
print(‘显示%s的主页‘ %name)
desk(‘chouchou‘)
shopcar(‘dd‘)
mina(‘kl‘)
标签:car lse war 购物 循环 pass rip 用户 strip
原文地址:https://www.cnblogs.com/lhqlhq/p/8746682.html