SAKURA-QiQi

导航

实验7

Admin_User

class User:
    """用户"""
    count = 0

    def __init__(self, name='guest', password=111111, status=1):
        User.count += 1
        self.name = name
        self.password = password
        self.status = status

    def info(self):
        if self.status == 1:
            print(f'{self.name},{self.password} 账户正常')
        else:
            print(f'{self.name},{self.password} 账户被封禁')

    def modify_password(self):
        """修改密码"""
        i = 0
        while i < 3:
            n = input("请输入旧密码:")
            if eval(n) == self.password:
                n = eval(input("输入新密码:"))
                print('密码修改成功!')
                self.password = n
                break
            else:
                i += 1
        else:
            print("账户已锁住,稍后再试")
            self.status = 0

    @classmethod  # 修饰符
    def show_count(cls):
        print(f"用户总数:{User.count}")

    def __del__(self):
        User.count -= 1


class Admin(User):
    """管理者"""

    def __init__(self, name='admin', password=999999, status=1):
        super().__init__(name, password, status)

    def info(self):
        print("管理者账户")
        super().info()

    def ban_user(self, user):
        user.status = 0

    def unblock_user(self, user):
        user.status = 1

    def reset_password(self, user):
        user.modify_password()


if __name__ == "__main__":
    u1 = User()
    u1.info()

    admin1 = Admin()
    admin1.info()
    User.show_count()

    admin1.ban_user(u1)
    u1.info()
    admin1.unblock_user(u1)
    u1.info()
    admin1.reset_password(u1)
    del u1
    User.show_count()

Task5

from Admin_User import User,Admin

u1 = User()
u1.info()
u1.modify_password()
u1.info()

admin1 = Admin()
admin1.reset_password(u1)
u1.info()
admin1.ban_user(u1)
u1.info()
admin1.unblock_user(u1)
u1.info()

 

posted on 2022-06-06 23:08  QiQi-sakura  阅读(7)  评论(1编辑  收藏  举报