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

实验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):
        n = 1
        while n <= 3:
            old_num = eval(input('请输入旧密码:'))
            if old_num == self._password:
                new_num = eval(input('请输入新密码:'))
                self._password = new_num
                print('密码修改成功')
                break
            else:
                n += 1
                if n == 3:
                    print('账户已锁,请稍后再试')
                    self._status = 0
                    break
                else:
                    print('密码错误,请重新输入:')


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.modify_password(self)

    def ban_user(self):
        User._status = 0
        print('账户已封禁')

    def unblock_user(self):
        User._status = 1
        print('账户已解封')


def main():
    u1 = User()
    u1.info()
    u1.modify_password()
    u1.info()
    a1 = Admin()
    a1.info()
    a1.reset_password()
    a1.ban_user()
    a1.unblock_user()



if __name__ == '__main__':
    main()

  

from user import User, Admin

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

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

  

 

标签:info,self,u1,u2,实验,._,password
来源: https://www.cnblogs.com/lezhangsen/p/16349873.html