实验七

user.py

复制代码
class user:
    def __init__(self,name="guest",password="111111",status="1"):
        self.name=name
        self.password=password
        self.status=status
    def info(self):
        print("用户名:"+self.name)
        print("密码:"+self.password)
        print("帐号状态:"+self.status)
    def modify_password(self):
        print("请输入旧密码:")
        x=input()
        n=0
        while x!=self.password:
            if n==2:
                print("账户已锁,请稍后再试。")
                return 0
            print("旧密码不对,请重新输入:")
            x=input()
            n=n+1
        print("请输入新密码")
        y=input()
        self.password=y


class Admin(user):
    def __init__(self,name="admin",password="999999",status=1):
        user.__init__(self,name,password,status)
    def reset_password(self,user1):
        x=input()
        user1.password=x
    def ban_user(self,user1):
        user1.status="0"
    def unblock_user(self,user1):
        user1.status="1"

复制代码

 

 

task5.py

from user import*
aaa=user()
aaa.info()
aaa.modify_password()

bbb=Admin()
bbb.reset_password(aaa)
aaa.info()
bbb.ban_user(aaa)
aaa.info()
bbb.unblock_user(aaa)
aaa.info()



复制代码

 

 

截图:

 

 

 

 

posted @ 2022-06-07 19:58  可爱捏  阅读(4)  评论(0编辑  收藏  举报