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

7

作者:互联网

class User:
    count = 0

    def __init__(m, name =  'guest', password = '111111', zt = '1'):
        User.count += 1
        m.name = name
        m.password = password
        m.zt = zt

    def info(m):
        if(m.zt == '1'):
            print(f'{m.name}, {m.password}, 账号正常')
        else:
            print(f'{m.name}, {m.password}, 账号封禁')

    def modify_password(m):
        n = 0
        while True:
            old_password = input('请输入旧密码:')
            if(old_password == m.password):
                new_password = input('请输入新密码:')
                m.password = new_password
                print('密码修改成功')
                break
            else:
                n = n + 1
                print('旧密码输入错误')
                if( n >= 3 ):
                    print('密码修改失败,账户已经锁定,请稍后再试')
                    break

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

    @classmethod
    def show_count(cls):
        print(f'用户总数:{User.count}')


u1 = User('Jack', '202185', '1')
u1.info()
u1.modify_password()
u1.info()

class User:
    count = 0

    def __init__(m, name =  'guest', password = '111111', zt = '1'):
        User.count += 1
        m.name = name
        m.password = password
        m.zt = zt

    def info(m):
        if(m.zt == '1'):
            print(f'{m.name}, {m.password}, 账号正常')
        else:
            print(f'{m.name}, {m.password}, 账号封禁')

    def modify_password(m):
        n = 0
        while True:
            old_password = input('请输入旧密码:')
            if(old_password == m.password):
                new_password = input('请输入新密码:')
                m.password = new_password
                print('密码修改成功')
                break
            else:
                n = n + 1
                print('旧密码输入错误')
                if( n >= 3 ):
                    print('密码修改失败,账户已经锁定,请稍后再试')
                    break

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

    @classmethod
    def show_count(cls):
        print(f'用户总数:{User.count}')

class Admin(User):

    def __init__(m, name = 'admin', password = '999999', zt = '1'):
        super().__init__(name, password, zt)
        m.name = name
        m.password = password
        m.zt = zt

    def info(m):
        print('管理员在此:', end='')
        if(m.zt == '1'):
            print(f'{m.name}, {m.password}, 账号正常')
        else:
            print(f'{m.name}, {m.password}, 账号封禁')

    def reset_password(m, x):
         x.password = '111111'
         print('已成功重置密码')

    def ban_user(m, x):
        User.count -= 1
        x.zt = '0'
        print('已封禁')

    def unblock_user(m, x):
        User.count += 1
        x.zt = '1'
        print('已解封')

a1 = Admin('x001')
a1.info()
User.show_count()

u1 = User('a001')
u1.info()
u1.modify_password()
u1.info()

a1.reset_password(u1)
u1.info()
a1.ban_user(u1)
User.show_count()
u1.info()
a1.unblock_user(u1)
u1.info()
User.show_count()

 

标签:,count,name,zt,User,print,password
来源: https://www.cnblogs.com/zy987/p/16343815.html