实验七

class User:
    count=0
    def __init__(self,name='guest',password=111111,state=1):
        self.name = name
        self.password = password
        self.state= state
        User.count+=1
    def info(self):
        if self.state==1:
            print(self.name,self.password,'正常')
        else:
            print(self.name, self.password,'异常')
    def modify_password(self):
        w = 1
        while True:
            a=eval(input('旧密码:'))
            if a!=self.password and w<=2:
                print("密码错误")
                w+=1
                continue
            elif w>2:
                print('锁定')
                self.state =0
                break
            elif a==self.password:
                e=eval(input("新密码:"))
                self.password=e
                print('修改成功')
                break
x1=User()
x1.info()
x1.modify_password()
x1.info()
print('用户数:',User.count)

class Admin(User):
    count = 0
    def __init__(self, name='admin', password=999999, state=1):
        User. __init__(self, name='admin', password=999999, state=1)
    def info(self):
        User.info(self)
    def modify_password(self):
        User.modify_password(self)
    def reset_password(self):
        q=eval(input('重置:'))
        self.password=q
        print('成功')
    def ban_user(self):
        self.state=0
        print('封禁')
    def unblock_user(self):
        self.state = 1
        print('解封')

x=Admin()
x.info()
x.modify_password()
x.info()
print('用户数:', User.count)
x.reset_password()
x.ban_user()
x.unblock_user()

  

 

 

 

posted @ 2022-06-08 09:46  一个幽灵  阅读(3)  评论(0编辑  收藏  举报