实验七

class User:
    num=0
    def __init__(self,name='guest',password='111111',status='1'):
        User.num+=1
        self.name=name
        self.password=password
        if status=='1':
            self.status='账号正常'
        else:
            self.status='账号已封禁'
    def show_count(self):
        print('用户总数 :',User.num)
    def info(self):
        print(self.name,self.password,self.status)
    def modify_password(self):
        n=input('请输入旧密码:')
        sum=2
        while sum<3:
            if n==self.password:
                n=input('请输入新密码:')
                self.password=n
                print('密码修改成功')
                break
            else:
                if sum == 0:
                    print('账号已封禁')
                    self.status = '账号已封禁'
                    break
                sum-=1
                n=input('输入旧密码:')
    def show_count():
        print(f'用户总数:{User.num}')
    def __del__(self):
        User.num-=1
u1=User()
u1.info()
u1.modify_password()
u1.info()
u2=User('a001','777')
u2.info()
User.show_count()


class Admin(User):
    def __init__(self,name='admin',password='999999',status='1'):
        super().__init__(name, password, status)
    def info(self):
        print('管理员账户')
        super().info()
    def reset_password(self,user):
        n1=input('请输入重置后的密码:')
        print('密码修改成功')
        user.password=n1
    def ban_user(self,user):
        user.status='账号已封禁'
    def unblock_user(self,user):
        user.status='账号正常'
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()

 

posted @ 2022-06-07 16:06  我真是想笑  阅读(4)  评论(0编辑  收藏  举报