装饰器作业
题目大概要求:
源代码:
log_in_status=False def log_in(f): def g(): global log_in_status if log_in_status==False: type=input("请选择登陆类型:1京东2微信") if(type=='1'): a=open("jingdong.txt") a.seek(0,0) USERNAME=a.readline() PASSWORD=a.readline() username=input("请输入用户名") password=input("请输入密码") if(USERNAME==(username+'\n') and PASSWORD==password): f() log_in_status=True else: print("用户名或密码错误") if(type=='2'): a=open("weixin.txt") a.seek(0,0) USERNAME=a.readline() PASSWORD=a.readline() username=input("请输入用户名") password=input("请输入密码") if(USERNAME==username+'\n' and PASSWORD==password): f() log_in_status=True else: print("用户名或密码错误") else: f() return g @log_in def home(): print("Welcome to home page") @log_in def finance(): print("Welcome to finance page") @log_in def book(): print("Welcom to book page") home() finance() book()