shadow824

导航

实验七

class User:
    def __init__(self, name='guest', password='111111', status='1'):
        self.name=name
        self.password=password
        self.status=status
    def modify_password(self):
        i=0
        while i<=3:
            x1=input('输入旧密码:')
            if x1!=self.password:
                i+=1
                if i==3:
                    print('账户已锁,请稍后再试。')
                    break
            else:
                x2=input('输入新密码:')
                print('密码修改成功!')
                break
    def info(self):
        print(f'用户名:{self.name} 密码:{self.password} 账号状态:{self.status}')


a1 = User('Joe', '5006692', 1)
a1.modify_password()

class Admin(User):
    def __init__(self, name='admin', password='999999', status='1'):
        User(). __init__(name, password, status)
    def info(self):
        User().info()
    def reset_password(self,user):
        user.password='999999'
    def ban_user(self,user):
        user.status='0'
    def unblock_user(self,user):
        user.status='1'
from user import User, Admin

u1 = User('Bob', '123456', '1')
u1.info()
u1.modify_password()
u1.info()

u2 = Admin('Joe', '654321', '1')
u2.info()
u2.reset_password(u1)
u2.ban_user(u1)
u1.info()
u2.unblock_user(u1)
u1.info()

 

posted on 2022-06-07 21:54  SHADOW&KING  阅读(42)  评论(1编辑  收藏  举报