Java教程

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

  

 

这篇关于实验7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!