赞
踩
- #创建账号数据库
- user_list = [{'username':'th','passwd':'baoweiluobu'},
- {'username':'my','passwd':'banjia'},
- {'username':'zy','passwd':'songsongsong'},
- ]
-
- #初始登录状态信息
- current_dic = {'username':None,'login':False}
-
- #带有验证功能的函数装饰器
- def auth_func(func):
- def wrapper(*args,**kwargs):
- if current_dic['username'] and current_dic['login']:
- res = func(*args,**kwargs)
- return res
- while True:
- username = input('请输入用户名')
- passwd = input('请输入密码')
- for user_dic in user_list:
- if username == user_dic['username'] and passwd == user_dic['passwd']:
- current_dic['username'] = username
- current_dic['login'] = True
- res = func(*args, **kwargs)
- return res
- else:
- print('用户名或密码错误')
-
- return wrapper
-
- @auth_func
- def index():
- print('欢迎来到天猫购物商城')
-
- @auth_func
- def shoppingcar():
- print('购物车:%s,%s,%s' %('葫芦娃','三明治','阿童木'))
-
- index()
- shoppingcar()

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。