from users import Users,Admin u1 = Users('戎',123456,1) u1.info() Admin.ban(1,u1) u1.info() Admin.unblock_user(1,u1) u1.info()
class Users: count = 0 def __init__(self,name='guest',password=111111,status=1): Users.count+=1 self.name = name self.password = password self.status = status def info(self): if self.status==1: print(f'账号:{self.name}正常\n密码:{self.password}') else: print(f'账号:{self.name}处于封禁状态\n密码:{self.password}') def modify_password(self): '''修改密码''' n = 0 while n < 3: i = input('输入旧密码:') if self.password == eval(i): i = eval(input('输入新密码:')) self.password = i print('密码修改成功!请重新登录!') break else: n+=1 else: print('密码封禁ing 请稍后再试') self.status=0 # @classmethod #修身符 def show_usernumbers(): '''查看用户数和管理员数量''' print(f'一共有{Users.count}个用户') def __del__(self): Users.count -= 1 class Admin(Users): count_adm=0 def __init__(self,name,password,status=1): Admin.count_adm+=1 super().__init__(name,password,status) def info(self): print('管理员01') super().info() def ban(self,user): user.status = 0 def reset_admpassword(self): super().modify_password() def show_Adiin(): print(f'现在有{Admin.count_adm}个管理员在线') def unblock_user(self,user): user.status=1 Users1 = Users() U1 = Users1.info() Users2 = Users('yes',123456) U2 = Users2.info() Admin.ban(0,Users1) Users1.info() Users.show_usernumbers()