实验七

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},账户正常')
            elif self.status==0:
                print(f'{self.name},{self.password},账户异常')

        def modify_password(self):
            old=input('输入旧密码:')
            if old==self.password:
                new=input('输入新密码:')
                self.password=new
                print('新密码修改成功')
            else:
                i=0
                while i<=3:
                    old=input('输入旧密码:')
                    if old == self.password:
                        new = input('输入新密码:')
                        self.password = new
                        print('新密码修改成功')
                        break
                    else:
                        i=i+1
                        if i==3:
                            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 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()

 

 

from 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 00:25  蒜头小兲  阅读(8)  评论(0编辑  收藏  举报

导航