实验七
user.py
class User(): def __init__(self,name="guest",password='111111',status=1): self._name=name self._password=password self._status=status def define(self): if self._status==1: return '账户正常' elif self._status==0: return '账户处于封禁状态' def info(self): print('-用户名,密码,账户状态:') print(f'{self._name},{self._password},{User.define(self)}') def modify_password(self): x=eval(input('请输入旧密码:')) if x==self._password: y=input('请输入新密码:') self._password=y print('修改密码成功') print(f'{self._name},{self._password},{User.define(self)}') else: n=0 while n<=1: z=input('输入错误,请重新输入:') n+=1 if n>1: print('账户已锁,请稍后再试') self._status=0 print(f'{self._name},{self._password},{User.define(self)}') a1=User('May',123456,1) a1.info() a1.modify_password()
task5.py
class User(): count = 0 def __init__(self, username='username', password='111', status='1'): self.username = username self.password = password self.status = status User.count += 1 def __del__(self): User.count -= 1 def info(self): if self.status == '1': print(f"{self.username}, {self.password}, 账户正常") else: print(f"{self.username}, {self.password}, 账户被封禁") def modify_password(self): for i in range(3): old_password = input("旧密码: ") if old_password == self.password: self.password = input("新密码: ") print("密码修改成功!") break elif i == 2: print("账户已锁, 请稍后再试...") self.status = '0' elif old_password != self.password: continue def show_count(): print(f"用户总数: {User.count}") class Admin(User): def __init__(self, username='Admin', password='999999', status='1'): super().__init__(username, password, status) def info(self): print("管理员账户: ") super().info() def reset_password(self, user): user.password = input("请输入你要修改的密码: ") def ban_user(self, user): user.status = '0' def unlock_user(self, user_name): user_name.status = '1' u1=User('User1','0000','1') u1.info() u1.modify_password() u1.info() admin1=Admin('Admin1','9999','1') admin1.info() User.show_count() admin1.reset_password(u1) admin1.ban_user(u1) u1.info() admin1.unlock_user(u1) u1.info() User.show_count()