实验七

class User:
    count=0
    def __init__(self,yonghuming='guest',mima='111111',status=1):
        User.count+=1
        self.yonghuming = yonghuming
        self.mima = mima
        self.status = status
    def info(self):
        if self.status ==1:
            s=self.yonghuming+','+self.mima+','+'正常状态'
        else:
            s=self.yonghuming+','+self.mima+','+'封禁状态'
        print(f'{s}')
    def modify_password(self):
        z=0
        for i in range(3):
            z+=1
            x = input('输入旧密码: ')
            if x == self.mima:
                print('密码输入正确')
                xiugai = input('输入新密码: ')
                self.mima = xiugai
                print('密码修改成功!')
                break
            else:
                if z==3:
                    print('账户已锁,请稍后再试')
                    self.status=0
                    User.count-=1
                print('旧密码输入错误')
                continue
    @classmethod
    def show_count(cls):
        print(f'用户总数:{User.count}')
class Admin(User):
    def __init__(self,yonghuming='admin',mima='999999',status=1):
        super().__init__(yonghuming,mima,status)
    def info(self):
        print('管理员账户')
        super().info()
    def reset_password(self,u):
        u.mima = '111111'
    def ban_user(self,u):
        u.status = 0
        User.count-=1
    def unblock_user(self,u):
        u.status = 1
        User.count+=1
def main():
    u1 = User()
    u1.info()
    admin1 = Admin('x001')
    admin1.info()
    User.show_count()
    admin1.ban_user(u1)
    u1.info()
    User.show_count()
    admin1.unblock_user(u1)
    u1.info()
    User.show_count()
    u2 = User('x002','123963')
    u2.info()
    User.show_count()
    admin1.reset_password(u2)
    u2.info()
    User.show_count()
if __name__=='__main__':
    main()

 

posted @ 2022-06-08 15:57  bamboosama  阅读(7)  评论(2编辑  收藏  举报