实验七

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):
        super().info()
    def reset_password(self,User):
        User.modify_password()
    def ban_user(self,User):
        self.status=0
    def un_block(self,User):
        self.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()

from fengzhuang import User,Admin

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

 

posted @ 2022-06-07 22:40  黄海祥  阅读(8)  评论(2编辑  收藏  举报