其他分享
首页 > 其他分享> > 实验七

实验七

作者:互联网

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()

 

标签:info,status,name,self,u1,实验,password
来源: https://www.cnblogs.com/dyh222/p/16334934.html