实验7 类和模块

task_5

class User:
    def __init__(self,name,password,status):
        if name=="" and password=="":
            self.name="guest"
            self.password="111111"
            self.status="1"
        else:
            self.name=name
            self.password=password
            self.status=status
    def info(self):
        print(f"用户名:{self.name}")
        print(f"密码:{self.password}")
        print(f"账号状态:{self.status}")
    def modify_password(self):
        flag=0
        while(flag<3):
            n=input("请输入原密码:")
            if n==self.password:
                flag=4
                n1=input("请输入新密码:")
                self.password=n1
                print("密码修改成功")
            else:
                flag+=1
        if flag==3:
            print("账户已锁,请稍后再试.")
class Admin(User):
    def __init__(self,name,password,status):
        if name=="" and password=="":
            self.name="admin"
            self.password="999999"
            self.status="1"
        else:
            self.name=name
            self.password=password
            self.status=status
    def reset_password(self,f):
        f.password="111111"
    def ban_user(self,f):
        f.status="0"
    def unblock_user(self,f):
        f.status="1"
def main():
    x = User("Bob", "12345", "1")
    y = Admin("Alex", "1112345", "1")
    x.info()
    y.info()
    y.reset_password(x)
    x.info()
    y.ban_user(x)
    x.info()
    y.unblock_user(x)
    x.info()
if __name__ == '__main__':
    main()

 

 

from user import User, Admin
x=User("","","")
y=Admin("Bob","12345","1")
x.info()
y.info()
x.modify_password()
x.info()
y.reset_password(x)
y.ban_user(x)
x.info()
y.unblock_user(x)
x.info()

 

 

posted on 2022-06-08 08:29  写作业的xzy  阅读(25)  评论(1编辑  收藏  举报