实验7

class User:
    def __init__(self,name='guest',password=111111,status=1):
        self.name=name
        self.password=password
        self.status=status
    def info(self):
        print('账户信息:')
        if self.status==1:
            print(f'用户名:{self.name},密码:{self.password},状态:状态正常')

        else:
            print(f'用户名:{self.name},密码:{self.password},状态:状态封禁')

    def modify_password(self):
        i=1
        while i<=3:
            n=eval(input('请输入旧密码:'))
            if n!=self.password and i<=2:
                i=i+1
            elif i==3 and n!=self.password:
                print('账户已锁,请稍后再试')
                self.status=0
                i=i+1
            else:
                n=eval(input('请修改密码:'))
                self.password=n
                print('密码修改成功')
                break
            
class Admin(User):
    def __init__(self,name="admin",password=999999,status=1):
        super().__init__(name,password,status)        
    def info(self):
        User.info(self)
    def reset_password(self,user):       
        user.modify_password()
    def ban_user(self,user):
        user.status=0
    def un_block(self,user):
        user.status=1
def main():
    user1=User()
    user1.info()
    admin1=Admin()
    admin1.info()

    admin1.reset_password(user1)
    user1.info()
    admin1.ban_user(user1)
    user1.info()
    admin1.un_block(user1)
    user1.info()
if __name__ == '__main__':    main()

class User():
    count = 0
    def __init__(self, username='username', password='111', status='1'):
        self.username = username
        self.password = password
        self.status = status
        User.count += 1

    def __del__(self):
        User.count -= 1

    def info(self):
        if self.status == '1':
            print(f"{self.username}, {self.password}, 账户正常")
        else:
            print(f"{self.username}, {self.password}, 账户被封禁")
    def modify_password(self):
        for i in range(3):
            old_password = input("旧密码: ")
            if old_password == self.password:
                self.password = input("新密码: ")
                print("密码修改成功!")
                break
            elif i == 2:
                print("账户已锁, 请稍后再试...")
                self.status = '0'
            elif old_password != self.password:
                continue

    def show_count():
        print(f"用户总数: {User.count}")


class Admin(User):
    def __init__(self, username='Admin', password='999999', status='1'):
        super().__init__(username, password, status)

    def info(self):
        print("管理员账户: ")
        super().info()
    def reset_password(self, user):
        user.password = input("请输入你要修改的密码: ")

    def ban_user(self, user):
        user.status = '0'

    def unlock_user(self, user_name):
        user_name.status = '1'


u1=User('账户1','0000','1')
u1.info()
u1.modify_password()
u1.info()

admin1=Admin('管理员1','9999','1')
admin1.info()
User.show_count()

admin1.reset_password(u1)
admin1.ban_user(u1)
u1.info()
admin1.unlock_user(u1)
u1.info()
User.show_count()

 

posted @ 2022-06-07 11:31  wfffww  阅读(5)  评论(1编辑  收藏  举报